View Full Version : Rotations- help?

08-03-2009, 12:46 PM
Hi All-
I am new to OpenGL and was wondering if anyone could offer some suggestions. I coded up a pyramid (rectangular base, triangular sides) by plotting all the vertices and currently each side is a different color. Hypothetically, we start with a red side and as it rotates it should go away in the back and then come back up as it makes the full 360. However, when I used glRotate it looks fine at first, but before the pyramid does a full rotation the front side somehow becomes transparent and I can see that red face in the back before it comes around. To avoid this problem, I thought I might be able to move the "camera" around, to view different parts of the pyramid to simulate a rotation instead of using glRotate. Any help is greatly appreciated! Thanks :)

08-03-2009, 01:41 PM
- check you request a depth buffer (aka. zbuffer).
- check all triangles are CCW (counterclockwise) from the visible side.

08-03-2009, 01:47 PM
Hey, thanks! For your second tip, do you mean check that the order I coded the triangles are CCW? / What's the reasoning behind that?

Another problem that arose was that the faces were rotating individually and not as a single pyramidal object, so is that another pro for just moving the "camera" around instead of directly calling glRotate?

08-03-2009, 04:29 PM
ZbuffeR said that vertices in your triangles must be specified in CCW order, reason behind that is backface culling. Quick reference: http://en.wikipedia.org/wiki/Back-face_culling ,
You can change this setting by calling glFrontFace ( http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/frontface.html )

To rotate whole object, call glRotatef before drawing that object.

ps. Sorry about my poor English.

08-07-2009, 10:52 PM
Alternatively, you can disable backface culling(glDisable(GL_CULL_FACE)), but for larger scenes you should have it on as it improves performance.