QT paintgl does not show anything on the screen
-
I am trying to draw some basic shapes using OpenGL.
void GLWidget::initializeGL() { glClearColor(0.5, 0.5, 0.5, 1.0); }
void GLWidget::paintGL() { glClear(GL_COLOR_BUFFER_BIT); // draw a red triangle glColor3f(1,0,0); glBegin(GL_POLYGON); glVertex2f(1,1); glVertex2f(1,6); glVertex2f(1,1); glEnd(); }
nothing shows on the window. also can not link glut, unfortunately!
-
Hi,
You don't seem to set the projection nor the modelview matrix so you are likely not looking in the right direction and maybe painting something that is too small to be seen.
-
@SGaist said in QT paintgl does not show anything on the screen:
modelview matrix
Thanks! I have now modified the code:
Now trying to plot a tetrahedron, which I got from an old textbook (qt4).void Tetrahedron::draw() { static const GLfloat P1[3] = { 0.0, -1.0, +2.0 }; static const GLfloat P2[3] = { +1.73205081, -1.0, -1.0 }; static const GLfloat P3[3] = { -1.73205081, -1.0, -1.0 }; static const GLfloat P4[3] = { 0.0, +2.0, 0.0 }; static const GLfloat * const coords[4][3] = { { P1, P2, P3 }, { P1, P3, P4 }, { P1, P4, P2 }, { P2, P4, P3 } }; glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0, 0.0, -10.0); glRotatef(rotationX, 1.0, 0.0, 0.0); glRotatef(rotationY, 0.0, 1.0, 0.0); glRotatef(rotationZ, 0.0, 0.0, 1.0); for (int i = 0; i < 4; ++i) { glLoadName(i); glBegin(GL_TRIANGLES); // qglColor (faceColors[i]); glColor3f(1,0.3,1); for (int j = 0; j < 3; ++j) { glVertex3f(coords[i][j][0], coords[i][j][1], coords[i][j][2]); } glEnd(); } }
the problem is qglColor (faceColors[I]); does not work anymore with the new qt version! I could not find out how this should be changed?
Also, almost every opengl code I (as a beginner) find on the internet is unusable with changes made in QT6, which brings me to the question what is the point of all the changes...
-
What do you mean by does not work anymore ?
As of the changes, OpenGL itself has seen quite a few versions since the Qt 4 times hence Qt has provided new interfaces that allow you to still use the old fixed pipeline but easily take advantage of the new one.