This program draws a cube except two opposite faces have been replaced by 2 lines to fulfill the whole 2 primitives thing.

To move the figure around in the XY plane, use WASD. I have not changed the glOrtho and glViewport to keep this consistent after rotations, so this will move the figure in whatever direction the original X and Y axes are currently pointing. You can select a rotation axis by pressing 1, 2 or 3 (For X, Y and Z). Then rotate the figure in the desired direction using '[' and ']'.

Answers to questions:

Answer 1:

Control is passed back to the programmer using a method that is called when the program needs to draw something to the window. This 'display' function contains the code to actually draw out the various shapes etc needed. During initialisation, we need to tell GLUT what method we use as our display function. This is done through a call to glutDisplayFunc(); which takes in the name of the desired display function as its only parameter.

Also, other functions like glutReshapeFunc(); and glutKeyboardFunc(); allow the programmer to define the behaviour of the program when events like keystrokes or a window resize are fired.

Answer 2:

The parameter to glutInitDisplayMode() is a disjunction of certain constants that tell GLUT whether:

- Single or double buffer will be used. Double buffering is a very common technique that is used to render the next frame completely in memory and then only display it to the screen when it is completely loaded. This prevents tearing of images and artifacts, and

- Colour format. This tells GLUT what type of colours will be used. For example, GL_RGB says that colours will be specified in terms of red, green and blue components.

Answer 3:

glOrtho(): The parameters to this function define the coordinate system for each of the 3 planes. For example, if the first two parameters to glOrtho are 0.0 and 1.0 and we draw something at 0.5 on the x-axis, it will be drawn in the middle of the window. If the two parameters were 0.0 and 5.0, it would be drawn a tenth of the width from the left of the window on the x-axis.

For the Z-plane, the line pointing out at the user is the positive axis while the line going into the screen is negative.

glViewport(): This defines how much of the window the programmer wants to use to draw. It takes 4 parameters - x and y of the bottom left point of the drawing 'canvas' and the width and height of the canvas.

If the window is resized, we might want to change the values in glOrtho() and glViewport depending on whether we want the image drawn to scale, to stay in its place, keep its size or be modified in any way. A new aspect ratio can be calculated based on what the programmer wants and the new mapping can be made with calls to glViewport() and glOrtho();