Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Depth Buffer and Stencil Buffer Issues QML

Tags:

c++

qt

opengl

qml

I'm using QML, and wanted to run custom OpenGL code. I created a custom Widget in C++ (extending QQuickItem) and overrided the paint function().
When I run my application, the console prints

QSGContext::initialize: depth buffer support missing, expect rendering errors
QSGContext::initialize: stencil buffer support missing, expect rendering errors

And just as it predicted, I do get rendering errors. I'll use a spider model as an example. Here's what it should like

spider stl

And here's what I'm getting enter image description here

I also don't know exactly how to describe it, but basically the opposite face (which should be blocked by the front face) is showing through as I rotate it.

I've managed to get rid of the depth buffer error with this:

void MyGLWidget::handleWindowChanged(QQuickWindow *win)
{
    if (win) {
        connect(win, SIGNAL(beforeSynchronizing()), this, SLOT(sync()), Qt::DirectConnection);
        connect(win, SIGNAL(sceneGraphInvalidated()), this, SLOT(cleanup()), Qt::DirectConnection);
        win->setClearBeforeRendering(false);
        QSurfaceFormat glFormat;
        glFormat.setVersion(3,2);
        glFormat.setProfile(QSurfaceFormat::CoreProfile);




        /*I'm showing everything for context, but this is the key line*/
        glFormat.setDepthBufferSize(1); 






        win->setFormat(glFormat);

    }
}

So now I'm only getting the stencil error, but that causes a different issue. One side is completely black, and doesn't show any of the lighting.

enter image description here

Some other background info: I'm displaying a QQuickView. My OpenGLWidget is imported into QML and embedded like so:

MyGLWidget {
    id: glWidget
}

In the paint() of my renderer, I am calling glEnable(GL_DEPTH_TEST) and glEnable(GL_STENCIL_TEST) at the top, but that doesn't seem to do anything. Maybe I'm calling that in the wrong context? I don't know where else I would be able to call it, however.

like image 717
faraza Avatar asked Oct 31 '15 10:10

faraza


2 Answers

As it turns out, all of my models (including the spider) had incorrect vertex normals, hence the shading issues. I should have checked them out in other rendering software.

glFormat.setDepthBufferSize(1) was the real fix

like image 96
faraza Avatar answered Nov 16 '22 15:11

faraza


Try

glDepthMask(GL_TRUE); 
// your paintings here
glDepthMask(GL_FALSE);

See also Scene Graph and Rendering.

like image 1
Dmitry Sokolov Avatar answered Nov 16 '22 13:11

Dmitry Sokolov