Jump to content
  • Advertisement
Sign in to follow this  
c_olin

Depth test not working

This topic is 3031 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts


For some reason depth testing does not seem to work in my application. As seen in this image. (The left arm should be in front of the torso).



My near clip distance is positive (1.0) and I cannot find any other reason why depth testing isn't working. Relevant code excerpts:


// Renderer init
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glDepthFunc(GL_LEQUAL);
glClearDepth(1.0f);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);

glViewport(0, 0, window->getWidth(), window->getHeight());

// Pre-render (every frame)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

gluPerspective(45.0, (double)window->getWidth()/(double)window->getHeight(), 1.0, 100.0);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

gluLookAt(0, 0, 0, 0, 0, -10, 0, 1, 0);

// Render
glColor4dv(renderOperation.material->diffuse.data());

glBindTexture(GL_TEXTURE_2D, renderOperation.material->texture->getId());

glBegin(GL_TRIANGLES);

for (auto vertex = renderOperation.vertices.begin(); vertex != renderOperation.vertices.end(); ++vertex) {
glTexCoord2dv((*vertex).second->data());
glVertex3dv((*vertex).first->origin.data());
}

glEnd();




Any ideas as to why this is not working correctly?

Share this post


Link to post
Share on other sites
Advertisement
It is very hard to tell with that image. disable culling and see if its a culling issue. Looks like you are not sending normals, so thats probably the issue.

Share this post


Link to post
Share on other sites
Quote:
Original post by Brother Bob
Do you even have a depth buffer? Check your code to initialize the rendering context.


I'm not sure what you mean by this. I have tried copy/pasting the initialization of OpenGL from a past project that I worked on where depth testing worked fine. But the results are the same. I know that I'm probably just missing something simple.

Can you be more specific?

Thanks for the help.

Share this post


Link to post
Share on other sites
Quote:
Original post by Brother Bob
Do you even have a depth buffer? Check your code to initialize the rendering context.


Ok... I've figured it out. I should have read the GLFW documentation more carefully.

Thanks for the help.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!