OpenGL Scenes

Don't do this lab until you've completed the previous Events lab.

Create a new directory for this lab and copy the cube program from the Events lab into it, with a new name. C programmers: copy the Makefile as well and update it. Java programmers: copy GlutWindow.java.

The goal is to translate your Py3D solar system model into a C or Java OpenGL program.

(Do not try to do everything at once! Start with the sun, then add a planet, and so on.)

In OpenGL, OpenGL glPushMatrix() and glPopMatrix() save and restore the current transformation state. glTranslatef, glRotatef, and glScalef apply a transformation that stays in effect until the next glPopMatrix(). The Py3D code

scene.begin(matrix.translate(1,2,3))
...
scene.end()
becomes in OpenGL
glPushMatrix();
glTranslatef(1,2,3);
...
glPopMatrix();

You will need to create one global/static variable for rendering spheres. This is what the C code looks like:

GLUquadricObj * QState;
...
QState = gluNewQuadric();
gluQuadricDrawStyle(QState, GLU_LINE);
The Java code looks like:
import javax.media.opengl.glu.*;
...
static GLUquadric QState = null;
...
QState = glu.gluNewQuadric();
glu.gluQuadricDrawStyle(QState, glu.GLU_LINE);

To draw a sphere, the C code will look like

glColor3f(red, green, blue);
gluSphere(QState, radius, slices, stacks);
where the slices and stacks values correspond to the tessellation values used in Py3D. For Java, remember to prefix methods and constants with gl. or glu.

The QState variable only needs to be created once and can be used to draw as many spheres as you like.

Section 8.6 of the textbook gives more detail about the various quadric surfaces that can be drawn using the GLU and GLUT libraries.

Animation

Add an idle handler to your program that animates the solar system rotation by updating the global day value.