I have a QtOpenglWidget with OpenGL 3.3 running and attempting to do instance rendering, but my z-buffer will not work
Currently, I add the 3 test cubes in draw order of cube3, cube2, then cube1 and changing it shows it is just displaying the last cube drawn. I also know DEPTH_TEST
is enabled as messing with glDepthFunc
will just not show anything.
My init:
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glClearDepth(1.0f);
glDepthFunc(GL_LEQUAL);
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
My Draw:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Vertex:
layout(location = 0) in highp vec3 position;
layout(location = 1) in highp mat4 modelToWorld;
uniform mat4 MVP;
out highp float DEPTH;
void main() {
gl_Position = MVP * modelToWorld * vec4(position, 1.0);
DEPTH = gl_Position.z / 20.0f;
}
Frag:
in highp float DEPTH;
out highp vec4 fColor;
void main() {
fColor = vec4(DEPTH, DEPTH, DEPTH,1.0);
}
EDIT
I am finding out this might be a QtWidget issue, The first thing being called in main
is
QSurfaceFormat format;
format.setVersion(3, 3);
format.setDepthBufferSize(24);
format.setStencilBufferSize(8);
format.setProfile(QSurfaceFormat::CoreProfile);
QSurfaceFormat::setDefaultFormat(format);