Wrong faces culled in OpenGL when drawing a rectangular prism
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/10/12
15:50 UTC
Read the original article
Hit count: 284
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