PDA

View Full Version : Trouble with cube



nergal
10-22-2002, 03:13 PM
A newbie question :) I tryed to work out a function that making a cube with parameters.
Problem is the cube doesn't look right. why?
code:
void createRoom(float langd, float hojd, float bredd, GLuint texture_id)
{
glPushMatrix();
glBindTexture ( GL_TEXTURE_2D, texture_id);
glBegin(GL_QUADS);
/*front*/
glTexCoord2f(1.0f, 0.0f); glVertex3f(0.0f, 0.0f, 0.0f); //bottom left
glTexCoord2f(1.0f, 1.0f); glVertex3f(langd, 0.0f, 0.0f); //bottom right
glTexCoord2f(0.0f, 1.0f); glVertex3f(langd, hojd, 0.0f); // top right
glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f, hojd ,0.0f); //top left
/*Back*/
glTexCoord2f(0.0f, 0.0f); glVertex3f(langd, 0.0f, bredd); //bottom right
glTexCoord2f(1.0f, 0.0f); glVertex3f(langd, hojd, bredd); //top right
glTexCoord2f(1.0f, 1.0f); glVertex3f(0.0f, hojd, bredd); // top left
glTexCoord2f(0.0f, 1.0f); glVertex3f(0.0f, 0.0f, bredd); //bottom left
/*Top*/
glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f, hojd, 0.0f); //top left
glTexCoord2f(1.0f, 0.0f); glVertex3f(0.0f, hojd, bredd); //bottom left
glTexCoord2f(1.0f, 1.0f); glVertex3f(langd, hojd,bredd); //bottom right
glTexCoord2f(0.0f, 1.0f); glVertex3f(langd, hojd, 0.0f); //top right
/*botten*/
glTexCoord2f(1.0f, 0.0f); glVertex3f(langd, 0.0f, 0.0f); //top right
glTexCoord2f(1.0f, 1.0f); glVertex3f(0.0f, 0.0f, 0.0f); //top left
glTexCoord2f(0.0f, 1.0f); glVertex3f(0.0f, 0.0f, bredd); //bottom left
glTexCoord2f(0.0f, 0.0f); glVertex3f(langd, 0.0f, bredd); //bottom right
/*Right*/
glTexCoord2f(1.0f, 0.0f); glVertex3f(langd, 0.0f, bredd); // bottom right
glTexCoord2f(1.0f, 1.0f); glVertex3f(langd, hojd, bredd); // top right
glTexCoord2f(0.0f, 1.0f); glVertex3f(langd, hojd, 0.0f); // top left
glTexCoord2f(0.0f, 0.0f); glVertex3f(langd, 0.0f, 0.0f); // bottom left
/*Left*/
glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f, 0.0f, 0.0f); //bottom left
glTexCoord2f(1.0f, 0.0f); glVertex3f(0.0f, 0.0f, bredd); //bottom right
glTexCoord2f(1.0f, 1.0f); glVertex3f(0.0f, hojd, bredd); //top right
glTexCoord2f(0.0f, 1.0f); glVertex3f(0.0f, hojd, 0.0f); //top left

glEnd();
glPopMatrix();
}

Bob
10-22-2002, 03:22 PM
Looked like a cube in my code... What exactly does "doesn't look right" mean for you?

nergal
10-23-2002, 02:24 AM
hm, strange, I mean that the sides doesn't look correct. Some sides seems to invisible and some sides seems to be triangles. But my values have to be correct (wrong order?) cause I wrote it down in an "plane in space" on paper.
Have u tryed to rotate the cube and see if all the sides are perfect?

Bob
10-23-2002, 08:57 AM
It looks correct from all angles. Invisible faces can be explained with face bulling. All faces of the cube don't have the same winding order; some faces are ordered clockwise, some counter clockwise. When turning on face culling, some faces will "incorrectly" be culled since they appear in the wrong order.

blood.angel
10-24-2002, 06:38 AM
Try drawing the cube without a texture. It could be your texture mapping is wrong.