1
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\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\$
    – Denis
    Commented May 28, 2016 at 22:40

1 Answer 1

0
\$\begingroup\$

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
\$\endgroup\$
3
  • \$\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
    Commented May 29, 2016 at 13:40
  • \$\begingroup\$ tnx for your tips \$\endgroup\$ Commented May 29, 2016 at 17:26
  • \$\begingroup\$ @HosseinNoroozpour Yeah, you are right. There was a bug with projection matrix. \$\endgroup\$
    – Denis
    Commented May 31, 2016 at 11:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .