I have been creating a simple 3D game in OpenGL.
I am attempting to draw a large 6 sided box. I have broken it down into drawing the 6 sides as 6 separate polygons. I had initially defined all the vertices separately, but have no created functions to define these vertices instead. In doing so I have now broken it. :o
The top and bottom sides of the box draw with no problems. However the front/back and two sides will not draw.
I have attached the relevant code in the hope that someone may be able to spot where I am going wrong. I appreciate any help you can offer.
void VerticesAlongX(int Distance, float StartValueX, float PositionY, float PositionZ, int Direction)
{
int i;
for (i = 0; i < Distance + 1; i++)
{
glVertex3f(StartValueX + i*(Direction), PositionY, PositionZ);
}
}
void VerticesAlongZ(int Distance, float PositionX, float PositionY, float StartValueZ, int Direction)
{
int i;
for (i = 0; i < Distance + 1; i++)
{
glVertex3f(PositionX, PositionY, StartValueZ + i*Direction);
}
}
void DrawBase()
{
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, ColourNormal);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specReflection);
glMateriali(GL_FRONT_AND_BACK, GL_SHININESS, 30);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// Translate the whole scene out and into view
// This is the initial viewing transformation
glTranslatef(0.0f, 0.0f, -35.0f);
//Left side -- Not Working
//glBegin(GL_POLYGON);
//glNormal3f(-1.0f, 0.0f, 0.0f);
//VerticesAlongZ(8, -12.0f, -12.0f, -7.0f, 1);
//VerticesAlongZ(7, -12.0f, -11.0f, 0.0f, -1);
//glEnd();
//Right side -- Not working
//glBegin(GL_POLYGON);
//glNormal3f(1.0f, 0.0f, 0.0f);
//VerticesAlongZ(7, 12.0f, -12.0f, 0.0f, -1);
//VerticesAlongZ(7, 12.0f, -11.0f, -7.0f, 1);
//glEnd();
//Back -- Notworking
//glBegin(GL_POLYGON);
//glNormal3f(0.0f, 0.0f, -1.0f);
//VerticesAlongX(24, 12.0f, -12.0f, -7.0f, -1);
//VerticesAlongX(24, -12.0f, -11.0f, -7.0f, 1);
//glEnd();
//Bottom
glBegin(GL_POLYGON);
glNormal3f(0.0f, -1.0f, 0.0f);
VerticesAlongX(24, -12.0f, -12.0f, 0.0f, 1);
VerticesAlongZ(7, 12.0f, -12.0f, 0.0f, -1);
VerticesAlongX(24, 12.0f, -12.0f, -7.0f, -1);
VerticesAlongZ(7, -12.0f, -12.0f, -7.0f, 1);
glEnd();
//Top Side
glBegin(GL_POLYGON);
glNormal3f(0.0f, 1.0f, 0.0f);
VerticesAlongX(24, -12.0f, -11.0f, 0.0f, 1);
VerticesAlongZ(7, 12.0f, -11.0f, 0.0f, -1);
VerticesAlongX(24, 12.0f, -11.0f, -7.0f, -1);
VerticesAlongZ(7, -12.0f, -11.0f, -7.0f, 1);
glEnd();
}