PDA

View Full Version : Unintended Lines And Boxes



Fezziwig
03-28-2012, 11:08 AM
I have a program which, simply put, is just a large collection of cuboid however, despite not being in the code, in release mode a random line comes out of every cuboid stretching on for infinity and in debug mode another cube appears this also stretches on for infinity. So I'm fairly sure its a compiler error but what causes these sort of wierd things?

These pictures might help.

release mode:
http://i.imgur.com/pksFf.png

debug mode:
http://i.imgur.com/XOq3e.png

and the cube drawing code if it helps.


glPushMatrix();
glBindTexture(GL_TEXTURE_2D, textures[1]);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL _REPEAT);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL _REPEAT);
glTranslatef(x, y, z);
glBegin(GL_QUADS);
glColor4f(1.0, 1.0, 1.0, 1.0);
//Top Face
glTexCoord2d(0.0, 0.0); glVertex3f(0, height, 0);
glTexCoord2d(0.0, depth/8); glVertex3f(0, height, depth);
glTexCoord2d(width/8, depth/8); glVertex3f(width, height, depth);
glTexCoord2d(width/8, 0.0); glVertex3f(width, height, 0);

//Bottom Face
glTexCoord2d(0.0, 0.0); glVertex3f(0, 0, 0);
glTexCoord2d(0.0, depth/8); glVertex3f(0, 0, depth);
glTexCoord2d(width/8, depth/8); glVertex3f(width, 0, depth);
glTexCoord2d(width/8, 0.0); glVertex3f(width, 0, 0);

//Right Face
glTexCoord2d(0.0,0.0); glVertex3f(0, 0, 0);
glTexCoord2d(depth/8, 0.0); glVertex3f(0, 0, depth);
glTexCoord2d(depth/8, height/8); glVertex3f(0, height, depth);
glTexCoord2d(0.0, height/8); glVertex3f(0, height, 0);

//Left Face
glTexCoord2d(0.0,0.0); glVertex3f(width, 0, depth);
glTexCoord2d(depth/8, 0.0); glVertex3f(width, 0, 0);
glTexCoord2d(depth/8, height/8); glVertex3f(width, height, 0);
glTexCoord2d(0.0, height/8); glVertex3f(width, height, depth);

//Front Face
glTexCoord2d(0.0,0.0); glVertex3f(width, 0, 0);
glTexCoord2d(width/8, 0.0); glVertex3f(0, 0, 0);
glTexCoord2d(width/8, height/8); glVertex3f(0, height, 0);
glTexCoord2d(0.0, height/8); glVertex3f(width, height, 0);

//Back Face
glTexCoord2d(0.0,0.0); glVertex3f(width, 0, depth);
glTexCoord2d(width/8, 0.0); glVertex3f(0, 0, depth);
glTexCoord2d(width/8, height/8); glVertex3f(0, height, depth);
glTexCoord2d(0.0, height/8); glVertex3f(width, height, depth);
glEnd();

glBegin(GL_LINES);
glColor4f(0.0, 0.0, 0.0, 1.0);

glVertex3f(0.0, 0.0, 0.0);
glVertex3f(width, 0.0, 0.0);
glVertex3f(width, 0.0, 0.0);
glVertex3f(width, 0.0, depth);
glVertex3f(width, 0.0, depth);
glVertex3f(0.0, 0.0, depth);
glVertex3f(0.0, 0.0, depth);
glVertex3f(0.0, 0.0, 0.0);

glVertex3f(0.0, height, 0.0);
glVertex3f(width, height, 0.0);
glVertex3f(width, height, 0.0);
glVertex3f(width, height, depth);
glVertex3f(width, height, depth);
glVertex3f(0.0, height, depth);
glVertex3f(0.0, height, depth);
glVertex3f(0.0, height, 0.0);

glVertex3f(0.0, 0.0, 0.0);
glVertex3f(0.0, height, 0.0);
glVertex3f(width, 0.0, 0.0);
glVertex3f(width, height, 0.0);
glVertex3f(width, 0.0, depth);
glVertex3f(width, height, depth);
glVertex3f(0.0, 0.0, depth);
glVertex3f(0.0, height,depth);

glEnd();
glPopMatrix();
}

trinitrotoluene
03-28-2012, 05:47 PM
if width,height and depth variables are defined as integer (int) , the result of the division by 8 will be an integer not a floating point number. To have a floating point number, divide by 8.0 or multiply by 0.125 . Example: 7/8 will be 0 . 7.0/8.0 will be 0.875 . Also, weird things can happen if some of your variables you use are not properly initialized.

Fezziwig
03-29-2012, 08:35 AM
It was an initialised variable in the cuboid class. I didn't realise that you needed to put in all variables in the setter