I set the format with:
QGLFormat format = QGLFormat(QGL::DoubleBuffer | QGL::DepthBuffer);
setFormat(format);
in the constructor.
Then in initializeGL I set depthTesting on.
void VoxelEditor::initializeGL()
{
glClearDepth(2000.0); // Enables Clearing Of The Depth Buffer
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LESS); // The Type Of Depth Test To Do
glShadeModel(GL_SMOOTH); // Enables Smooth Color Shading
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
}
In paintGL I clear the depth buffer.
void VoxelEditor::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
draw();
}
I remember it used to work with less vertices, so it might be that I'm using too many for the depthbuffer to handle(?). I have 32*32*32 voxels which are drawn half of most of the time, so 98304 quads.
Depth testing however still does not work and shows the quads in order of execution.