Hello,
I have been working on drawing primitives using glBegin(GL_QUAD) and glEnd(). I’m specifically trying to render a simple cube.
However, upon rendering only the first two faces render, the next four don’t render at all. I’m not sure why, because the data itself is right, and upon printing to console window the data looks right, yet the other four sides don’t seem to want to render. The first two sides render perfectly.
I’ve color coded each face so that I know which side is being rendered, and have commented out the normals for now.
Anyone have any ideas? I’m sure I’m not doing something at the most basic level!
I placed the key code below.
Many thanks!
CODE:
struct face {
GLint a;
GLint b;
GLint c;
GLint d;
};struct Vert {
GLfloat i;
GLfloat j;
GLfloat k;
GLfloat x;
GLfloat y;
GLfloat z;
};Vert verts[8] = {
{ 0.577349185944,0.577349185944,-0.577349185944,
1.0,1.0,-1.0 },
{ 0.577349185944,-0.577349185944,-0.577349185944,
1.0, -1.0, -1.0 },
{ -0.577349185944,-0.577349185944,-0.577349185944,
-1.0,-1.0,-1.0 },
{ -0.577349185944,0.577349185944,-0.577349185944,
-1.0,1.0,-1.0 },
{ 0.577349185944,0.577349185944,0.577349185944,
1.0,1.0,1.0 },
{ 0.577349185944,-0.577349185944,-0.577349185944,
1.0,-1.0,1.0 },
{ -0.577349185944,-0.577349185944,0.577349185944,
-1.0,-1.0,1.0 },
{ -0.577349185944,0.577349185944,0.577349185944,
-1.0,1.0,1.0}
};face faces[6]={
{0, 1, 2, 3},
{4, 7, 6, 5},
{0, 4, 5, 1},
{1, 5, 6, 2},
{2, 6, 7, 3},
{4, 0, 3, 7}
};void display(void)
{
/* clear all pixels */
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);/* draw white polygon (rectangle) with corners at
- (0.25, 0.25, 0.0) and (0.75, 0.75, 0.0)
*/
glRotatef(60.0, 1.0, 0.0, 0.0);
//glRotatef(45.0, 0.0, 1.0, 0.0);
for (int i=0;i<6;i++) {
if (i == 0)
glColor3f(1.0,0.0,0.0); // Red
else if (i == 1)
glColor3f(0.0,1.0,0.0); // Green
else if (i == 2)
glColor3f(1.0,1.0,0.0); // Yellow
else if (i == 3)
glColor3f(0.0,0.0,1.0); // Blue
else if (i == 4)
glColor3f(1.0,0.0,1.0); // Magenta
else
glColor3f(0.0,1.0,1.0); // Cyan
glBegin(GL_QUADS);
//glNormal3f(verts[faces[i].a].i,verts[faces[i].a].j,
verts[faces[i].a].k);
glVertex3f(verts[faces[i].a].x,verts[faces[i].a].y,
verts[faces[i].a].z);
//glVertex3fv(verts[faces[i].a]);
//glNormal3f(verts[faces[i].b].i,verts[faces[i].b].j,
verts[faces[i].a].k);
glVertex3f(verts[faces[i].b].x,verts[faces[i].b].y,
verts[faces[i].a].z);
//glNormal3f(verts[faces[i].c].i,verts[faces[i].c].j,
verts[faces[i].a].k);
glVertex3f(verts[faces[i].c].x,verts[faces[i].c].y,
verts[faces[i].a].z);
// glNormal3f(verts[faces[i].d].i,verts[faces[i].d].j,
verts[faces[i].a].k);
glVertex3f(verts[faces[i].d].x,verts[faces[i].d].y,
verts[faces[i].a].z);
glEnd();
}
/* don’t wait!
- start processing buffered OpenGL routines
*/
glFlush ();
}