dangerChihuahua007
dangerChihuahua007

Reputation: 20895

After enabling depth testing in OpenGL, my entire screen is blank (reverts to clear color) - why?

In my C++ graphics application using OpenGL and GLUT, I want to enable depth testing via

glEnable(GL_BLEND);
glEnable(GL_DEPTH_TEST);

However, these two lines of code clear my screen, which is now just the clear color. I was wondering why.

I am just supposed to have a few primitive solid spheres and cubes.

Upvotes: 1

Views: 2922

Answers (2)

joe
joe

Reputation: 2309

Make sure you're also drawing between your Z near and Z far values after enabling depth testing.

Upvotes: 1

Drew Hall
Drew Hall

Reputation: 29055

Sounds like you've forgotten to clear the depth buffer and are thus failing the depth test due to whatever preexisting garbage is in the depth buffer memory. Try to add GL_DEPTH_BUFFER_BIT to your glClear() call, like so:

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

Good luck!

Upvotes: 12

Related Questions