gluLookAt question

Started by
2 comments, last by silversaraph 18 years, 5 months ago
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.
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
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.
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?

This topic is closed to new replies.

Advertisement