Drawing a rectangular prism using opengl

Posted by BadSniper on Game Development See other posts from Game Development or by BadSniper
Published on 2012-09-23T23:06:46Z Indexed on 2012/09/24 3:51 UTC
Read the original article Hit count: 4521

Filed under:
|
|

I'm trying to learn opengl. I did some code for building a rectangular prism. I don't want to draw back faces so I used glCullFace(GL_BACK), glEnable(GL_CULL_FACE);. But I keep getting back faces also when viewing from front and also sometimes when rotating sides are vanishing. Can someone point me in right direction?

glPolygonMode(GL_FRONT,GL_LINE); // draw wireframe polygons
glColor3f(0,1,0); // set color green
glCullFace(GL_BACK); // don't draw back faces
glEnable(GL_CULL_FACE); // don't draw back faces
glTranslatef(-10, 1, 0); // position

     glBegin(GL_QUADS);


     // face 1
     glVertex3f(0,-1,0);
     glVertex3f(0,-1,2);
     glVertex3f(2,-1,2);
     glVertex3f(2,-1,0);

     // face 2
     glVertex3f(2,-1,2);
     glVertex3f(2,-1,0);
     glVertex3f(2,5,0);
     glVertex3f(2,5,2);

     // face 3
     glVertex3f(0,5,0);
     glVertex3f(0,5,2);
     glVertex3f(2,5,2);
     glVertex3f(2,5,0);

     // face 4
     glVertex3f(0,-1,2);
     glVertex3f(2,-1,2);
     glVertex3f(2,5,2);
     glVertex3f(0,5,2);

     // face 5
     glVertex3f(0,-1,2);
     glVertex3f(0,-1,0);
     glVertex3f(0,5,0);
     glVertex3f(0,5,2);

     // face 6
     glVertex3f(0,-1,0);
     glVertex3f(2,-1,0);
     glVertex3f(2,5,0);
     glVertex3f(0,5,0);

     glEnd();

© Game Development or respective owner

Related posts about opengl

Related posts about 3d