PDA

View Full Version : Problems with Culling faces



Tea
06-08-2002, 11:59 PM
Hello. This is my first post here.(sorry about spelling)

Got a prob with culling faces. I've enabled it using glEnable(GL_CULL_FACE).

Then i load my scene, and i walk and mouselook , i cant' see some faces (about half of them).

There'are about 10 textured cubes in my scene, and my render loop look like this :

{
glClear buffers
glLoadIdentity

glRotates(for camera)
glTranslates (for camera)

drawcubes()
}

nothing wrong , yes?
I tryed glCullFace(GL_BACK), and glCullFace(GL_FRONT), but i still can't see some walls.

thanks!

Jan
06-09-2002, 12:24 AM
Hi,

certainly your problem has something to do with the winding of the polys.
If you enable culling, that means, that OpenGL will not draw polygons that you can only see from the back (GL_BACK) or from the front (GL_FRONT). So if you are on the back side of a poly and you look at it, you won´t see it. You could disable culling, then you see every polygon, or you have to tell gl proberly, which side is the front and which is the back.

If you create a quad you have to use 4 vertices. If you say vertex 1 is at -1|1 (top left) and vertex 2 is at -1|-1 (bottom left) and vertex 3 is at 1|-1 (bottom right) and vertex 4 is at 1|1 (top right), than you created those vertices in a counter-clockwise winding (against the direction of the clock). So OpenGL thinks that the side you are looking at is the front. If you specify the vertices the other way round (-1|1; 1|1; 1|-1; -1|-1) gl thinks it is the back side.

If you enable culling it is important to create the vertices in a special order so that they are really drawn, when you want them to be drawn. If you disable culling it doesn´t matter, how you create your vertices.

Hope that helps you.
Jan.

Tea
06-09-2002, 01:54 AM
thank you very much!
I created all quad's vertices in clockwise order. I'm going to rewrite function..

kurko
06-10-2002, 02:32 AM
you could use glFrontFace(GL_CCW), too.