Rendering of Complex Shapes

I got a new user question that I can’t seem to find answers to. I created a complex shape using the following code:

glBegin(GL_POLYGON); // Drawing Using Triangles
glVertex3f( -2.0f,-2.0f, 0.0f); //
glVertex3f( 2.0f,-2.0f, 0.0f); //
glVertex3f( 2.0f,2.0f, 0.0f); //
glVertex3f( 1.0f,3.0f, 0.0f); //
glVertex3f( -1.0f,3.0f, 0.0f); //
glVertex3f( -2.0f,2.0f, 0.0f); //

Then I used many other Polygons and quads to make this into a 3D object. My question is, how do I make it so the sides of this object that are not in the field of view of the camera don’t show up? Right now, it is a very complex picture, that is hard to understand what is going on, because the backside of the 3D object show up just like the front. But when I use the glutSolidCube(3.0f) command, it looks like it should, but the cube is not the shape that I need. Is there some sort of trick with lighting that I can use? Thanks for any help, Newbie

If your model is convex, enabling culling should do the trick:

glEnable( GL_CULL_FACE );
glCullFace( GL_BACK );

If it isn’t convex, you’ll need to enable depth buffering.

I am not sure what you mean by if my model is convex. I inserted the lines that you listed above and nothing changed. Does convex pertain to which direction I drew my vertexes? Either clockwise or counterclockwise? For I drew everything in a counterclockwise direction. Thanks for the help. Newbie

Sounds like you have not enabled depth testing.

Did you define all polys counter clockwise?
Depth-test shouldn’t have anything to do with backface culling I think.

Depth-test IS relevant if the model isn’t convex, i.e. if some front-facing polys should appear behind other front-facing polys. Culling on its own isn’t enough here.

In my program I enable depth testing by the following code:

glEnable (GL_DEPTH_TEST);

And when I do this, the screen stays totally black. But when I comment it out, my complex shape and my cylinder both appear. Do I need to do something else besides the enable to make this work? I also have Lighting, Lighto and Cull_Face enabled.

May I ask what a convex shape is though? Does it have to do with the counterclockwise means of defining my shapes? And what is the difference between Cull_Face and Depth_Test?


Can you e-mail your code ?

My e-mail address is available when clicking on the question mark near the “posted 12-5-2000…”.

It seems really strange that we cannot find the solution to this (usually) simple problem.