Take the 2-minute tour ×

I've looked at a ton of articles and SO questions about OpenGL not drawing, common mistakes, etc. This one is stumping me.

I've tried several different settings for glOrtho, different vertex positions, colors, etc., all to no avail.

I can confirm the OpenGL state is valid because the clear color is purple in the code (meaning the window is purple). gDEBugger is also confirming frames are being updated (so is Fraps).

Here is the code. Lines marked as "didn't help" were not there originally, and were things that I tried and failed.

QTWindow::QTWindow( )
    // Enable mouse tracking

void QTWindow::initializeGL()
    // DEBUG
    debug("Init'ing GL");
    this->makeCurrent(); ///< Didn't help
    this->resizeGL(0, 0); ///< Didn't help
    glDisable(GL_CULL_FACE); ///< Didn't help
    glClearColor(1, 0, 1, 0);

void QTWindow::paintGL()
    // DEBUG
    debug("Painting GL");
    this->swapBuffers(); ///< Didn't help

void QTWindow::resizeGL(int width, int height)
    // DEBUG
    debug("Resizing GL");
    glOrtho(0, 1000, 0, 1000, -1, 1);

The triangle is not being displayed at all, even with culling turned off. However, all three debug logs are called exactly how they should be.

What am I missing?

share|improve this question
So basically, you're getting a purple screen (as a result of glClearColor and glClear), but there is not triangle drawing? Just want a clarification... –  Forgive Goto Feb 8 '13 at 2:23
Correct. I've tried with quads, and I'm just literally trying different things with no rhyme or reason at this point. I removed the calls to makeCurrent and changed updateGL to just update. Still nothing. –  Qix Feb 8 '13 at 2:24

2 Answers 2

Try calling glViewport() function at the very beginning of the QTWindow::resizeGL() function:

glViewport(0, 0, width, height);

And don't ever call resizeGL() with width and height set to 0 ;) Besides that, it is not necessary for you to call resizeGL() directly as it is being called by Qt whenever the window is being resized.

You can remove all calls to the swapBuffers() function - it is being called internally by Qt.

The makeCurrent() function should be called before all other GL calls, so it is good that you have called it in initializeGL(), but you don't have to call it in the paintGL() function (unless paintGL() is being called from another thread, but I bet it isn't in your code).

share|improve this answer
All of that was debug code to get something to work. I realize what resizeGL did with 0,0. I know about glViewport. I know about makeCurrent. I mentioned all of that in the OP. –  Qix Feb 11 '13 at 3:43
up vote 0 down vote accepted

The issue ended up being versions. The version string returned with glGetString(GL_VERSION) indicated 4.2 compatibility context was being used.

Since the triangle calls in the paintGL method were removed in 3.1 (if I recall correctly), it was obvious why they weren't drawing anything. Further, no errors were being thrown because it was in compat. mode.

Because I couldn't get the version down below 3.0 on the QGLWidget (due to the fact that QT requires 2.1, as I was informed on another message board), I set the version to 3.0 and tried using some 3.0 drawing calls and it ended up working.

share|improve this answer

Your Answer


