2

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?

4

2 回答 2

0

尝试在 QTWindow::resizeGL() 函数的最开始调用 glViewport() 函数:

glViewport(0, 0, width, height);

并且永远不要调用 resizeGL() 并将宽度高度设置为 0 ;) 除此之外,您不必直接调用 resizeGL() ,因为每当调整窗口大小时 Qt 都会调用它。

您可以删除对 swapBuffers() 函数的所有调用 - 它是由 Qt 在内部调用的。

makeCurrent() 函数应该在所有其他 GL 调用之前被调用,所以最好在 initializeGL() 中调用它,但您不必在 paintGL() 函数中调用它(除非正在调用 paintGL()从另一个线程调用,但我敢打赌它不在你的代码中)。

于 2013-02-10T22:26:49.773 回答
0

问题最终成为版本。glGetString(GL_VERSION)正在使用带有指示的 4.2 兼容性上下文返回的版本字符串。

由于paintGL方法中的三角形调用在 3.1 中被删除(如果我没记错的话),很明显为什么它们没有绘制任何东西。此外,没有抛出错误,因为它是兼容的。模式。

因为我无法在 QGLWidget 上将版本降至 3.0 以下(由于 QT 需要 2.1,正如我在另一个留言板上获悉的那样),我将版本设置为 3.0 并尝试使用一些 3.0 绘图调用并结束起来工作。

于 2013-02-11T03:45:36.357 回答