Jump to content
  • Advertisement
Sign in to follow this  
silversaraph

OpenGL gluLookAt question

This topic is 4644 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

Hi all, I have just finish a camera using gluLookAt() and make a simple world to test it. Everything seems ok when I only have the land and the sky , i can move and turn the camera like im walking in that world, but when I finally put some other objects in the world, none of these objects can be displayed currectly. I think the depth test is wrong. When I move the camera to the back of something and see it, all the polygons face to me is invisble and the back side of the polygons on the oppsite side is shown. I wonder if anyone know how to let the depth test in OpenGL to follow the gluLookAt function, thanks and sorry for my english. ps: Everytime a scene was rendered, I firstly clear the color and depth buffer, then use glLoadIdentity, then set camera, finally draw the objects.

Share this post


Link to post
Share on other sites
Advertisement
Make sure depth buffering is enabled (glEnable(GL_DEPTH_TEST)) and that your window was created with a depth buffer (how to do this depends on the windowing library you use, e.g. in glut this is set using glutInitDisplayMode(...)).

Another possible cause of this problem is related to backface culling. The behaviour of your objects could mean that their triangles are not consistently defined clockwise (cw) or counter-clockwise (ccw). A simple test to check if this is in fact the case, is to disable backface culling (glDisable(GL_CULL_FACE)). If that solves it, you can keep that statement in as a solution to your problem. However, a nicer solution would be to re-order the vertices within the triangles of your models to be consistently cw (or ccw, depending on the glFrontFace(...) type you use).

Tom

Share this post


Link to post
Share on other sites
Your problem is that you probably have the wrong culling face enabled, or your vertex ordering is incorrect. What is happening is OpenGL is not displaying what you expect because it thinks those polygons are interior faces. This depends on the order of vertices (generally all your vertices need to be specified in either clockwise or counter-clockwise order). Look up GL_CULL_MODE, glCullFace and glFrontFace.

Share this post


Link to post
Share on other sites
Thanks all and great thanks Tom, I made everything right except that the z-buffer of my window need to be 24 bits(it was 16), and now it works:)
May I ask you guys another question, that is I load a .3ds model in, but I can have the model displayed as it should be only when the camera stay close enough to it, or it looks like broken and flicks when i turnning the camera, anyone knows why?

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!