I know web pages should be past this, but this site doesn't look right on IE.
I will fix it some day ( not for IE 6 though) but for now this is easier and a lot more fun.

Download firefox or chrome or hide this message forever...

The Color Cube




For the past two tutorials we have been using GLUT (Graphics Library Utility Toolkit) to draw our teapot. This time we are going to make our own shape ( a cube ) using vertices. We are going to replace the line of code: glut.glutTeapot(1.0f); with our cube.


  • We have to draw each face of the cube separately. This is done by sending the vertex of each corner down the graphics pipeline
    • gl.glBegin(GL.GL_POLYGON);
      gl.glVertex3d(x1, y1, z1);
      gl.glVertex3d(x2, y2, z2);
      gl.glVertex3d(x3, y3, z3);
      gl.glVertex3d(x4, y4, z4);
      gl.glEnd();
    • The vertices must be sent down the graphics pipeline in counter clockwise order. This is the default way that OpenGL interprets the front of the object.
  • The color blending effect is done automatically by OpenGL. Before I sent the the vertex down the graphics pipeline, I set a color for that vertex. OpenGL uses that to interpolate the color between vertices on the polygon.
    • gl.glBegin(GL.GL_POLYGON);
      gl.glColor3d(x1, y1, z1);
      gl.glVertex3d(x1, y1, z1);
      gl.glColor3d(x2, y2, z2);
      gl.glVertex3d(x2, y2, z2);
  • On to the next one...