Game Development Reference
In-Depth Information
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -zvalue);
glRotatef(rot[0], 1.0f, 0.0f, 0.0f);
glRotatef(rot[1], 0.0f, 1.0f, 0.0f);
glRotatef(rot[2], 0.0f, 0.0f, 1.0f);
DrawCube();
glutSwapBuffers();
}
Drawing some geometry
All OpenGL drawing is sandwiched between a 'glBegin' and a 'glEnd'.
'glBegin' has a single constant parameter that tells the renderer how to
work with the data passed. In this example we are using four vertex
polygons or quads . OpenGL interprets each set of four vertices as a
polygon. We first give a new colour so that each face has a different
colour, then a list of four vertices using the OpenGL function 'glVertex3f'.
Having drawn the six faces that make up the cube, we finish with a 'glEnd'
call.
void DrawCube(void)
{
glBegin(GL_QUADS);
// front
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(-10.0f, -10.0f, 10.0f);
glVertex3f(10.0f, -10.0f, 10.0f);
glVertex3f(10.0f, 10.0f, 10.0f);
glVertex3f(-10.0f, 10.0f, 10.0f);
// back
glColor3f(0.0f, 1.0f, 0.0f);
glVertex3f(10.0f, -10.0f, -10.0f);
glVertex3f(-10.0f, -10.0f, -10.0f);
Search Nedrilad ::




Custom Search