Hi,
I am just starting with OpenGL, but have a fair bit of programming knowledge in other fields.
To get used to the API, I started drawing a simple rotating cube onto the screen.
My demo program draws the cube and rotates it, but there is a very odd problem, to which I have thus been unable to find an answer:
The cube is composed by individual quad faces. As soon as the rotation goes over a certain point, it seems, that OpenGL is drawing the back face on top of the front face, resulting in some weird escheresk geometry.
I added two screenshots to this post, to further illustrate the problem.
Also, the drawing function looks like this:
<div class=“ubbcode-block”><div class=“ubbcode-header”>Click to reveal… <input type=“button” class=“form-button” value=“Show me!” onclick=“toggle_spoiler(this, ‘Yikes, my eyes!’, ‘Show me!’)” />]<div style=“display: none;”>
-
(void) draw:(int) delta_t{
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_QUADS);
{
glColor3f(1.0f,0.5f,0.0f); // Set The Color To Orange
glVertex3f(s,-1s, s); // Top Right Of The Quad (Bottom)
glVertex3f(-1s,-1s, s); // Top Left Of The Quad (Bottom)
glVertex3f(-1s,-1s,-1s); // Bottom Left Of The Quad (Bottom)
glVertex3f( s,-1s,-1s); // Bottom Right Of The Quad (Bottom)glColor3f(0.0f,s,0.0f); // Set The Color To Green glVertex3f( s, s,-1*s); // Top Right Of The Quad (Top) glVertex3f(-1*s, s,-1*s); // Top Left Of The Quad (Top) glVertex3f(-1*s, s, s); // Bottom Left Of The Quad (Top) glVertex3f( s, s, s); // Bottom Right Of The Quad (Top) glColor3f(s,0.0f,0.0f); // Set The Color To Red glVertex3f(s,s,s); // Top Right Of The Quad (Front) glVertex3f(-1*s,s,s); // Top Left Of The Quad (Front) glVertex3f(-1*s,-1*s,s); // Bottom Left Of The Quad (Front) glVertex3f(s,-1*s,s); // Bottom Right Of The Quad (Front) /*glVertex3f(myTriangle.alpha_x+myTriangle.location_x, myTriangle.alpha_y+myTriangle.location_y, myTriangle.alpha_z); glVertex3f(myTriangle.beta_x+myTriangle.location_x, myTriangle.beta_y+myTriangle.location_y, myTriangle.beta_z); glVertex3f(myTriangle.gamma_x+myTriangle.location_x, myTriangle.gamma_y+myTriangle.location_y, myTriangle.gamma_z);*/
}
glEnd();
glRotatef(5, 1, 1, 1);glFlush();
}
[/QUOTE]</div>
What am I doing wrong here? Do I really need to change the order of the faces halfway through an animation? Is there maybe a better attempt to rotation than this?
Thanks for the help and kind regards,
The Raven