PDA

View Full Version : extra quads are being displayed with GL_QUADS...



avanindra
10-01-2009, 06:49 PM
Hi All,

I am trying to display voxels in opengl. I made a function to display cubes. when I display one or two cubes , the function works fine but when I increase the number of cubes, extra quad strips are being displayed. I am pasting one function that is displaying some extra quad strips. I expected below function to display five cubes, but rather it is displaying five cubes with some extra quad strips:

unsigned int displayCubes()
{
float x_vox = 0, y_vox = 0, z_vox = 0, x_step = 1, y_step = 1, z_step = 1;

int iDisplayListNum = glGenLists(1);
glNewList(iDisplayListNum,GL_COMPILE);
glBegin(GL_QUADS);

for(int i=0; i <5; i++)
{


x_vox = i;
y_vox = i;
z_vox = i;

glColor3f(0.3,0.8,0.7);
glVertex3f(x_vox ,y_vox ,z_vox);
glVertex3f(x_vox ,y_vox + y_step ,z_vox);
glVertex3f(x_vox + x_step ,y_vox + y_step ,z_vox);
glVertex3f(x_vox + x_step ,y_vox ,z_vox);


glColor3f(0.3,0.8,0.7);
glVertex3f(x_vox + x_step ,y_vox ,z_vox);
glVertex3f(x_vox + x_step ,y_vox + y_step ,z_vox);
glVertex3f(x_vox + x_step ,y_vox + y_step ,z_vox+z_step);
glVertex3f(x_vox + x_step ,y_vox ,z_vox+z_step);

glColor3f(0.3,0.8,0.7);
glVertex3f(x_vox + x_step ,y_vox ,z_vox+z_step);
glVertex3f(x_vox + x_step ,y_vox + y_step ,z_vox+z_step);
glVertex3f(x_vox ,y_vox + y_step ,z_vox+z_step);
glVertex3f(x_vox ,y_vox ,z_vox+z_step);

glColor3f(0.3,0.8,0.7);
glVertex3f(x_vox ,y_vox ,z_vox+z_step);
glVertex3f(x_vox ,y_vox + y_step ,z_vox+z_step);
glVertex3f(x_vox ,y_vox + y_step ,z_vox);
glVertex3f(x_vox ,y_vox ,z_vox);

glColor3f(0.3,0.8,0.7);
glVertex3f(x_vox ,y_vox ,z_vox);
glVertex3f(x_vox + x_step ,y_vox ,z_vox);
glVertex3f(x_vox + x_step ,y_vox ,z_vox+z_step);
glVertex3f(x_vox ,y_vox ,z_vox+z_step);

glColor3f(0.3,0.8,0.7);
glVertex3f(x_vox + x_step ,y_vox + y_step ,z_step);
glVertex3f(x_vox ,y_vox + y_step ,z_step);
glVertex3f(x_vox ,y_vox + y_step ,z_vox+z_step);
glVertex3f(x_vox + x_step ,y_vox + y_step ,z_vox+z_step);





}
glEnd();

glEndList();


return iDisplayListNum;


}




Please help me point out where I am doing the error.