   Problem with OpenGL (beginners stuff)
  Having small problems with one of the earlier tutorial problems.I am using Visual Studio 2005 and glut (which you can probably see) Problem #1: The 'pyramid' that I have drawn there always draws its sides in the same order, so as it rotates it appears to be see through on some sides. I could of sworn there was a matrix mode that fixed that up, but I can not seem to find it.Problem #2: Is it possible to do this without the push/pop matrix calls in the draw function? The NeHe tutorial does not have them, but the other tutorial that I got the glut stuff from does. If I just take them out now the 'pyramid' then has both rotations applied to it instead of just the one intended for it.#include <windows.h>#include <gl\gl.h>#include <gl\glu.h>#include <gl\glut.h>GLfloat rotateT, rotateS;static void draw(void);int main(int argc, char **argv){glutInit(&argc,argv);glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);glutCreateWindow("This be my window");glutDisplayFunc(draw);glutIdleFunc(draw);glMatrixMode(GL_PROJECTION);gluPerspective(50,1,0.0,200.0);glMatrixMode(GL_MODELVIEW);glutMainLoop();  return 0;}static void draw(void){glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glPushMatrix();glTranslatef(-1.5,0,-6);glRotatef(rotateT,0,1,0);glBegin(GL_TRIANGLES);glColor3f(1,0,0);glVertex3f(0,1,0);glColor3f(0,1,0);glVertex3f(1,-1,1);glColor3f(1,1,0);glVertex3f(-1,-1,1);glColor3f(1,0,0);glVertex3f(0,1,0);glColor3f(1,1,0);glVertex3f(-1,-1,1);glColor3f(0,0,1);glVertex3f(-1,-1,-1);glColor3f(1,0,0);glVertex3f(0,1,0);glColor3f(0,0,1);glVertex3f(-1,-1,-1);glColor3f(1,0,1);glVertex3f(1,-1,-1);glColor3f(1,0,0);glVertex3f(0,1,0);glColor3f(1,0,1);glVertex3f(1,-1,-1);glColor3f(0,1,0);glVertex3f(1,-1,1);glEnd();glLoadIdentity();glTranslatef(1.5f,0.0f,-6.0f);glRotatef(rotateS,1,0,0);glColor3d(255,0,0);glBegin(GL_QUADS);glVertex3f(-1,1,0);glVertex3f(1,1,0);glVertex3f(1,-1,0);glVertex3f(-1,-1,0);glEnd();glPopMatrix();rotateT += 0.02;rotateS -= 0.15;glutSwapBuffers();}
  First off where is your projection setup code at? e.g. glOrtho or gluPerspective?YOu need to set your near/far planes up to say 1.0 and 100.0glPushMatrix and glPopMatrix are your friends. Learn them you will need the later on...You should call them like so with the code you have belowstatic void draw(void){glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glLoadIdentity();glPushMatrix();glTranslatef(-1.5,0,-6);glRotatef(rotateT,0,1,0);glBegin(GL_TRIANGLES);glColor3f(1,0,0);glVertex3f(0,1,0);glColor3f(0,1,0);glVertex3f(1,-1,1);glColor3f(1,1,0);glVertex3f(-1,-1,1);glColor3f(1,0,0);glVertex3f(0,1,0);glColor3f(1,1,0);glVertex3f(-1,-1,1);glColor3f(0,0,1);glVertex3f(-1,-1,-1);glColor3f(1,0,0);glVertex3f(0,1,0);glColor3f(0,0,1);glVertex3f(-1,-1,-1);glColor3f(1,0,1);glVertex3f(1,-1,-1);glColor3f(1,0,0);glVertex3f(0,1,0);glColor3f(1,0,1);glVertex3f(1,-1,-1);glColor3f(0,1,0);glVertex3f(1,-1,1);glEnd();glPopMatrix();glPushMatrix();glTranslatef(1.5f,0.0f,-6.0f);glRotatef(rotateS,1,0,0);glColor3d(255,0,0);glBegin(GL_QUADS);glVertex3f(-1,1,0);glVertex3f(1,1,0);glVertex3f(1,-1,0);glVertex3f(-1,-1,0);glEnd();glPopMatrix();rotateT += 0.02;rotateS -= 0.15;glutSwapBuffers();};  @#1:You have specified all Triangles in the same order, so you can either use backfaceculling or enable the DepthTest.for backfaceculling use: glCullFace(GL_FRONT); glEnable(GL_CULL_FACE);for hidden surface removal use glEnable(GL_DEPTH_TEST); glClearDepth(1.0f);both belong to the main function after glMatrixMode(...) is called.   ;  Mars, the gluPerspective is there in the main between the two matrixmode calls    glMatrixMode(GL_PROJECTION);   gluPerspective(50,1,0.0,200.0);   glMatrixMode(GL_MODELVIEW);Ok, I see what the cull face did, made only one side of the plane visible (as is evident by the flipping square that dissapears). This works fine on the pyramid but only because all the planes are facing outward. (if I reverse one of the planes (by switching the order of two of its points) it gets drawn over the top again)The depth test makes the whole thing flicker really badly, and makes all sides of the pyramid appear see through (although that could be due to flickering altering images, not sure) I did try the depth code before, after, and inbetween the matrixmode calls, made no difference.;  Your program have two major mistakes.Firstly, the near clip plane of perspective matrix cannot be placed at zero distance.  Otherwise, it will mess up the calculation.  And, you should change it like this.gluPerspective(50, 1, 0.1, 200.0);Secondly, you must have depth test enabled for your 3D model to be drew correctly.  Otherwise, any triangles draw later will overwrite the previous one.To enable depth test, you need to insert the following lines at the initialization.  glEnable( GL_DEPTH_TEST );Culling is a good practice to boost the framerate.  But, it is usually not necessary for drawing a 3D model correctly.  To take the advantage offered by culling, your 3D model should be closed and should have a consistant winding.  Roughly speaking, it can double the framerate in some cases.   ;Quote:Original post by TamGarTrinKiOk, I see what the cull face did, made only one side of the plane visible (as is evident by the flipping square that dissapears). This works fine on the pyramid but only because all the planes are facing outward. (if I reverse one of the planes (by switching the order of two of its points) it gets drawn over the top again)The depth test makes the whole thing flicker really badly, and makes all sides of the pyramid appear see through (although that could be due to flickering altering images, not sure) I did try the depth code before, after, and inbetween the matrixmode calls, made no difference.Jep, that's right, the culling just works when all your triangles are specified in the same order, but you'd better do that anyway.The GLUT_DOUBLE in conjunction with glutSwapBuffers() should eliminate the flickering effect. Don't know why it doesn't. i'm not using Depth test in my application, so probably someone else has a better answer to that. @my_hty: true, new clipping plane set to 0 means that your imageplane is a dot instead of a plane. Maybe OpenGL changed it internally.;  Ah, that did it, once I set that near clipping plane to 0.1 instead of 0.0 the depth test no longer made it flicker and solved the drawing behind other planes.Ok, so push/pop calls added in, culling added, depth added, near plane shifted and now on to making that cube more completeThanks all for help.Fixed and the current working code.#include <windows.h>#include <gl\gl.h>#include <gl\glu.h>#include <gl\glut.h>GLfloat rotateT, rotateS;static void draw(void);int main(int argc, char **argv){glutInit(&argc,argv);glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);glutCreateWindow("This be my window");glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);glutDisplayFunc(draw);glutIdleFunc(draw);glMatrixMode(GL_PROJECTION);gluPerspective(50,1,0.1,200.0);glMatrixMode(GL_MODELVIEW);glCullFace(GL_FRONT);glEnable(GL_CULL_FACE);glEnable(GL_DEPTH_TEST);glutMainLoop();  return 0;}static void draw(void){glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);//PyramidglPushMatrix();glTranslatef(-1.5,0,-6);glRotatef(rotateT,0,1,0);//Pointy bitsglBegin(GL_TRIANGLES);//Face 1glColor3f(1,0,0);glVertex3f(0,1,0);glColor3f(0,1,0);glVertex3f(1,-1,1);glColor3f(1,1,0);glVertex3f(-1,-1,1);// Face 2glColor3f(1,0,0);glVertex3f(0,1,0);glColor3f(1,1,0);glVertex3f(-1,-1,1);glColor3f(0,0,1);glVertex3f(-1,-1,-1);// Face 3glColor3f(1,0,0);glVertex3f(0,1,0);glColor3f(0,0,1);glVertex3f(-1,-1,-1);glColor3f(1,0,1);glVertex3f(1,-1,-1);//Face 4glColor3f(1,0,0);glVertex3f(0,1,0);glColor3f(1,0,1);glVertex3f(1,-1,-1);glColor3f(0,1,0);glVertex3f(1,-1,1);glEnd();// BaseglBegin(GL_QUADS);glColor3f(0,1,0);glVertex3f(1,-1,1);glColor3f(1,0,1);glVertex3f(1,-1,-1);glColor3f(0,0,1);glVertex3f(-1,-1,-1);glColor3f(1,1,0);glVertex3f(-1,-1,1);glEnd();glPopMatrix();//To be cubeglPushMatrix();glTranslatef(1.5f,0.0f,-6.0f);glRotatef(rotateS,1,0,0);glColor3d(1,0,0);glBegin(GL_QUADS);// Face 1glVertex3f(-1,1,0);glVertex3f(1,1,0);glVertex3f(1,-1,0);glVertex3f(-1,-1,0);glEnd();glPopMatrix();rotateT += 0.02;rotateS -= 0.15;glutSwapBuffers();}