Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
OpenGL not rendering properly
electrohamster last edited by
Not entirely sure why this isn't working. I suspect there is something subtly different about OpenGL in Qt that I'm not using correctly.
I've Created a QDeclarativeView using a QGLWidget as the Viewport and a class derived from QGraphicsScene as the scene. With the below test code the view is properly cleared to blue but I can't see the polygon that I'm drawing. I'm able to run the test OpenGL applications fine.
void OpenGLScene::drawBackground(QPainter *painter, const QRectF &rect)
float width = float(painter->device()->width());
float height = float(painter->device()->height());
glClearColor( 0.0f, 0.0f, 1.0f, 1.0f );
glOrtho( -5.0f, 5.0f, -5.0f, 5.0f, -1.0f, 1.0f );
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin( GL_POLYGON );
glColor4f(1.0, 1.0, 1.0, 1);
glVertex2f( -5.0f, -5.0f );
glVertex2f( 5.0f, -5.0f );
glColor4f(0.0, 1.0, 0.0, 1);
glVertex2f( 5.0f, 0.0f );
glVertex2f( -5.0f, 0.0f );
MalcolmD last edited by
sorry, not in a position to test any code, but if this is all the opengl code then I would think you'd see something flying off the screen. First of all, i think the glOrtho() call should be made with the glMatrixMode as projection, since that's the projection transformation.
Second of all, the ortho call is being made every frame, so what ever matrix is on the top of the stack, so it is just getting completely warped.
While you are at it, i'm not so sure the matrices initialize to identity, so a glLoadIdentity() call when the model view matrix is up would maybe help. Not sure. anyhow, good luck.