PDA

View Full Version : drawing a box



fox
12-14-2000, 04:47 AM
Hi is there a more efficient way of generating a box - also can a file format be written to generate these boxes ?

glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, BlueSurface);
glBegin(GL_POLYGON);
glNormal3d( 0.0, 0.1, 0.0);
glVertex3d( x1, y1, -z1);//FRIGHT
glVertex3d( -x1, y1, -z1);//FLEFT
glVertex3d( -x1, y1, z1);//NLEFT
glVertex3d( x1, y1, z1);//NRIGHT
glEnd();

//Front face of cube

glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, PurpleSurface);
glBegin(GL_POLYGON);
glNormal3d( 0.0, 0.0, 0.3);
glVertex3d( -x2, y1, z1);//top right corner
glVertex3d( -x1, y1, z1);//top left corner
glVertex3d( -x1, -y1, z1);//bottom left corner
glVertex3d( -x2, -y1, z1);//bottom right corner
glEnd();



glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, BlueSurface);
glBegin(GL_POLYGON);
glNormal3d( 0.0, 0.0, 0.2);
glVertex3d( -x3, y1, z1); //top right corner
glVertex3d( -x2, y1, z1); //top left corner
glVertex3d( -x2, -y1, z1); //bottom left corner
glVertex3d( -x3, -y1, z1); //bottom right corner
glEnd();
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, PurpleSurface);
glBegin(GL_POLYGON);
glNormal3d( 0.0, 0.0, 0.3);
glVertex3d( x3, y1, z1);//top right corner
glVertex3d( -x3, y1, z1);//top left corner
glVertex3d( -x3, -y1, z1);//bottom left corner
glVertex3d( x3, -y1, z1);//bottom right corner
glEnd();

glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, BlueSurface);
glBegin(GL_POLYGON);
glNormal3d( 0.0, 0.0, 0.2);
glVertex3d( x2, y1, z1); //top right corner
glVertex3d( x3, y1, z1); //top left corner
glVertex3d( x3, -y1, z1); //bottom left corner
glVertex3d( x2, -y1, z1); //bottom right corner
glEnd();


glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, PurpleSurface);
glBegin(GL_POLYGON);
glNormal3d( 0.0, 0.0, 0.3);
glVertex3d( x1, y1, z1);//top right corner
glVertex3d( x2, y1, z1);//top left corner
glVertex3d( x2, -y1, z1);//bottom left corner
glVertex3d( x1, -y1, z1);//bottom right corner
glEnd();

glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, BlueSurface);
//horizontal right face
glBegin(GL_POLYGON);
glNormal3d( 0.3, 0.0, 0.0);
glVertex3d( x1, y1, -z1);//FTOP
glVertex3d( x1, y1, z1);//NTOP
glVertex3d( x1, -y1, z1);//NBOTTOM
glVertex3d( x1, -y1, -z1);//FBOTTOM

glEnd();

//Back face of cube
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, BlueSurface);
glBegin(GL_POLYGON);
glNormal3d( 0.0, 0.0, -0.3);
glVertex3d( -x1, y1, -z1);//top left
glVertex3d( x1, y1, -z1);//top right
glVertex3d( x1, -y1, -z1);//bottom right
glVertex3d( -x1, -y1, -z1);//bottom left
glEnd();

//horizontal left face
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, BlueSurface);
glBegin(GL_POLYGON);
glNormal3d( -0.4, 0.0, 0.0);
glVertex3d( -x1, y1, z1);//NTOP
glVertex3d( -x1, y1, -z1);//FTOP
glVertex3d( -x1, -y1, -z1);//FBOTTOM
glVertex3d( -x1, -y1, z1);//NBOTTOM
glEnd();
//Bottom face of cube
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, BlueSurface);
glBegin(GL_POLYGON);
glNormal3d( 0.0, -0.1, 0.0);
glVertex3d( x1, -y1, z1);//NRIGHT
glVertex3d( -x1, -y1, z1);//NLEFT
glVertex3d( -x1, -y1, -z1);//FLEFT
glVertex3d( x1, -y1, -z1);//FRIGHT
glEnd();


thanx