Qt5とOpenGLを使用してビューポートを操作したいのですが、ビューポートが移動しません。
mouseMoveEventで移動値を設定し、paintGLまで値(_x)は渡っているようなのですが、glTraslatedが機能しないのはなぜなのでしょうか。
Qt: 5.5.0
cpp:
1#include <QOpenGLFunctions> 2#include <QOpenGLWidget> 3#include <QQuaternion> 4#include <gl/GLU.h> 5#include <QDebug> 6 7class MyGLViewer : public QOpenGLWidget, protected QOpenGLFunctions 8{ 9public: 10 MyGLViewer(QWidget *parent) 11 : QOpenGLWidget(parent) 12 , _x(0.0){ } 13 14 void initializeGL() 15 { 16 initializeOpenGLFunctions(); 17 glClearColor(1.0f, 1.0f, 1.0f, 1.0f); 18 } 19 20 void resizeGL(int w, int h) 21 { 22 glViewport(0, 0, w, h); 23 glMatrixMode(GL_PROJECTION); 24 glLoadIdentity(); 25 gluPerspective(35.0, (double)w / (double)h, 1.0, 1000.0); 26 gluLookAt(28.0, 21.0, 28.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); 27 qDebug() << "resizeGL"; 28 } 29 30 void drawGrid() 31 { 32 glColor3d(0.0, 0.0, 0.0); 33 glBegin(GL_LINES); 34 glVertex3d( 0.0, 0.0, 10.0 ); 35 glVertex3d( 0.0 , 0.0, -10.0 ); 36 glEnd(); 37 38 glBegin(GL_LINES); 39 glVertex3d( 10.0, 0.0, 0.0 ); 40 glVertex3d( -10.0 , 0.0, 0.0 ); 41 glEnd(); 42 } 43 44 void paintGL() 45 { 46 47 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 48 glTranslated(_x, 0.0, 0.0); 49 drawGrid(); 50 } 51 52 void mouseMoveEvent(QMouseEvent *) 53 { 54 qDebug() << "MOVE"; 55 _x += 0.1; 56 paintGL(); 57 } 58 59private: 60 GLdouble _x; 61 62};
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。