   Problem with rotation cube
  Hello everyone.I try to make a rotating cube for a homework in my Opengl course.I managed to make something but the problem is that, when the cube is rotating, the front face of the cube is being covered by the back face of it.I must make it vice-versa.The front face must cover the back face.Pls see the code i post and and suggest me a solution.Thanks in advance!!PS:My code:#include<GL/glut.h>#include<GL/glu.h>#include<math.h>#include<stdlib.h>#include<time.h>#define pi 3.14#define Pleura 1typedef float point3[3];int n;float theta[3]={0.0,0.0,0.0},mege8os=0;int axis=2;int flag=1;point3point[]={{1,1,0},{1,-1,0},{-1,-1,0},{-1,1,0}};void idle(){theta[0]+=1;if (theta[0] > 360.0){theta[0]-=360;flag=-flag;}/*mege8os+=6/720;if(mege8os>6)mege8os+=6/720;*/glutPostRedisplay();}void display(){glNewList(Pleura,GL_COMPILE);glBegin(GL_POLYGON);glVertex3fv(point[0]);glVertex3fv(point[1]);glVertex3fv(point[2]);glVertex3fv(point[3]);glEnd();glEndList();glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);glLoadIdentity();glColor3f(0.5,0.5,0.5);glTranslatef(0,0,-110);glRotatef(theta[0],1.0,1.0,1.0);//glTranslatef(0,0,-110);if(flag==1)glScalef(1+theta[0]/60,1+theta[0]/60,1+theta[0]/60);if(flag==-1)glScalef(1+(360-theta[0])/60,1+(360-theta[0])/60,1+(360-theta[0])/60);//glScalef(6.0,6.0,6.0);//pleura(point[0], point[1], point[2], point[3]);//glRotatef(120,1,1,1);//-----------------------------------------------------------------glPushMatrix();glTranslatef(0,0,1);glColor3f(0,1,1);glCallList(Pleura);//pleura(point[0], point[1], point[2], point[3]);glPopMatrix();glPushMatrix();//--------------------------------------------------------------------glTranslatef(0,0,-1);glColor3f(1,0,1);glCallList(Pleura);//pleura(point[0], point[1], point[2], point[3]);glPopMatrix();glPushMatrix();//--------------------------------------------------------------------glTranslatef(0,1,0);glRotatef(90,1,0,0);glColor3f(0,1,0);glCallList(Pleura);//pleura(point[0], point[1], point[2], point[3]);glPopMatrix();glPushMatrix();//-----------------------------------------------------------------------glTranslatef(0,-1,0);glRotatef(90,1,0,0);glColor3f(1,0,0);glCallList(Pleura);//pleura(point[0], point[1], point[2], point[3]);glPopMatrix();glPushMatrix();//-----------------------------------------------------------------------glTranslatef(1,0,0);glRotatef(90,0,1,0);glColor3f(1,1,0);glCallList(Pleura);//pleura(point[0], point[1], point[2], point[3]);glPopMatrix();glPushMatrix();//------------------------------------------------------------------------glTranslatef(-1,0,0);glRotatef(-90,0,1,0);glColor3f(1,1,1);glCallList(Pleura);//pleura(point[0], point[1], point[2], point[3]);glPopMatrix();glutSwapBuffers();}void myinit(){glMatrixMode(GL_PROJECTION);glLoadIdentity();glOrtho(-30.0,30.0,-30.0,30.0,-120.0,120.0);glMatrixMode(GL_MODELVIEW);glClearColor(0.0,0.0,0.0,0.0);glColor3ub(0,0,0);}void main(int argc, char** argv){srand( (unsigned)time( NULL ) );glutInit(&argc,argv);glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);glEnable(GL_DEPTH_TEST);glutInitWindowSize(500,500);glutCreateWindow("Rotating Cube");glutDisplayFunc(display);glutIdleFunc(idle);myinit();glutMainLoop();}   
  Your problem is probably due to the fact that your faces are facing inwards. Reverse your vertex declarations for the faces.   ;Quote:Original post by ToohrVykYour problem is probably due to the fact that your faces are facing inwards. Reverse your vertex declarations for the faces.every face has only one side??i thought that when i declare one polygon is the same from the both sides..what do u mean to reverse the declarations??write an example please.thanks in advance man.;  Wow, that took far too long to debug.  Must be getting rusty.  ToohrVyk is wrong since you don't enable face culling.  The actual problem is here:void main(int argc, char** argv){srand( (unsigned)time( NULL ) );glutInit(&argc,argv);glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);glEnable(GL_DEPTH_TEST); // attempt to call OpenGL functionglutInitWindowSize(500,500);glutCreateWindow("Rotating Cube"); // don't obtain an OpenGL context until hereglutDisplayFunc(display);glutIdleFunc(idle);myinit();glutMainLoop();}Every OpenGL function must operate with a valid OpenGL context.  Since you do not have a valid context when you call glEnable the call is ignored and depth testing is never turned on.  Move the glEnable(GL_DEPTH_TEST); call below the glutCreateWindow call.By the way, you shouldn't recreate your display list every frame.  Create it just once in the init function.Enigma   ;Quote:Original post by EnigmaWow, that took far too long to debug.  Must be getting rusty.  ToohrVyk is wrong since you don't enable face culling.  The actual problem is here:void main(int argc, char** argv){srand( (unsigned)time( NULL ) );glutInit(&argc,argv);glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);glEnable(GL_DEPTH_TEST); // attempt to call OpenGL functionglutInitWindowSize(500,500);glutCreateWindow("Rotating Cube"); // don't obtain an OpenGL context until hereglutDisplayFunc(display);glutIdleFunc(idle);myinit();glutMainLoop();}Every OpenGL function must operate with a valid OpenGL context.  Since you do not have a valid context when you call glEnable the call is ignored and depth testing is never turned on.  Move the glEnable(GL_DEPTH_TEST); call below the glutCreateWindow call.By the way, you shouldn't recreate your display list every frame.  Create it just once in the init function.Enigmait worked of course.what a silly mistake :Pthanks also for the advice.I really enjoy OpenGL.