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;

In my init function I set GL_CULL_FACE and GL_DEPTH_TEST:

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

    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;

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

  • \$\begingroup\$ 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. \$\endgroup\$ – user3051029 May 28 '16 at 22:40

First of all, please give a complete source code of (small error-prone version of) your project, because this kind of problem depends on lots of things.

However, there are lots of reasons that can make unwanted black screen, most common mistakes that I can guess in your case, are:

  • mathematics mistakes
    • camera matrix (in your case see your clipping range)
    • shader mistakes
  • scissor test (check if your scissor is correctly working)
  • soon or late clearing of framebuffer
| improve this answer | |
  • \$\begingroup\$ We typically ask users to post their code here, and not having it uploaded somewhere else, mainly for 3 reasons: 1) we're lazy and don't want to do extra steps to see the core of the question, 2) expect the user to narrow down the location of the issue and 3) external sources may become invalid, and thus make the question no longer relevant. Thus you should ask them to add more code to the question (please do it in the comments of the question), but not to upload their code somewhere. \$\endgroup\$ – Vaillancourt May 29 '16 at 13:40
  • \$\begingroup\$ tnx for your tips \$\endgroup\$ – Hossein Noroozpour May 29 '16 at 17:26
  • \$\begingroup\$ @HosseinNoroozpour Yeah, you are right. There was a bug with projection matrix. \$\endgroup\$ – user3051029 May 31 '16 at 11:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.