1

Currently I am writing a small application with Qt and OpenGl and I choosed QOpenGLWidget for rendering graphics.

That's how I declared my widget:

class GLWidget : public QOpenGLWidget, protected QOpenGLFunctions{
     // Methods, slots, e.t.c
}

And that's the constructor:

GLWidget::GLWidget(QWidget *parent) : QOpenGLWidget(parent)
{
    /* Tried this, it didn't help.
    QSurfaceFormat format;
    format.setDepthBufferSize(24);
    this->setFormat(format);
    */
}

In my init function I set GL_CULL_FACE and GL_DEPTH_TEST:

void GLWidget::initializeGL()
{
    /* Some initialization stuff regarding the scene */

    glEnable(GL_CULL_FACE);
    glEnable(GL_DEPTH_TEST);
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

}

And I really don't know why the widget renders the black screen. Here are some pictures. First one: with disabled GL_CULL_FACE and disabled GL_DEPTH_TEST. enter image description here

Second one: with enabled GL_CULL_FACE and disabled GL_DEPTH_TEST. Maybe it's not a good picture, but I can assure you, you can see some surfaces through the other. enter image description here

Third one: with enabled GL_CULL_FACE and enabled GL_DEPTH_TEST. Actually, it doesn't matter if GL_CULL_FACE is enabled. Anyway it renders the black screen. enter image description here

And here's the image without any shading just to show you that the model is fine. enter image description here

I tried to set the format manually, but it didn't help. Still the black screen:

QSurfaceFormat format;
format.setDepthBufferSize(24);
this->setFormat(format);

Oh and yes, I set glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); at the beginning of my paintGL() function.

Denis
  • 719
  • 2
  • 8
  • 23
  • By the way, if I try to set the version with `format.setVersion(3, 2);`, it also renders the black screen. I am not sure, but I think it's somehow related to the problem. – Denis May 28 '16 at 22:39
  • 1
    Have you tried testing your code with a simple cube? Also, I think it'd help to share your shader code and your paintGL() function. See also this reply: http://stackoverflow.com/questions/34381314/qopenglwidget-show-black-screen?rq=1. How did you configure OpenGL support for Qt? – Rethunk May 29 '16 at 17:24
  • 1
    @Rethunk There was a bug with projection matrix. The problem is solved now. – Denis May 31 '16 at 11:20
  • glad you were able to fix it with a matrix tweak. Having the pictures posted may help someone else in the future. Good luck with the rest of your implementation. – Rethunk May 31 '16 at 13:28

0 Answers0