Question

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
    this->setMouseTracking(true);
}

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->makeCurrent(); ///< Didn't help
    glLoadIdentity();
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(0,1,1);
    glBegin(GL_TRIANGLES);
    glVertex2f(500,100);
    glVertex2f(100,500);
    glVertex2f(0,0);
    glEnd();
    this->swapBuffers(); ///< Didn't help
}

void QTWindow::resizeGL(int width, int height)
{
    // DEBUG
    debug("Resizing GL");
    this->makeCurrent(); ///< Didn't help
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, 1000, 0, 1000, -1, 1);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}

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?

Was it helpful?

Solution 2

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.

OTHER TIPS

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).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top