CS 488: Assignment 1


Out: 1/21/03

Due: 2/11/03 at 2:00pm

In this first assignment you will start learning OpenGL by implementing a bouncing ball application - basically a non-competitive version of the 70s game of pong. This program will introduce you to the GLUT routines, how to structure a graphics program in terms of callbacks, the basic OpenGL calls, and the hardware we have availble to run the software on.

You can find a shell of the program here and a simple Makefile here

If you want to do this on OS-X you will also need to either download the latest apple version of glut, or this resource file mac.r

The shell contains the calls to the GLUT routines which deal with opening an appropriate graphics window, accepting keyboard commands, and setting up the appropriate display loops. The program shell initially opens a 2D orthographic projection double-buffered window that is 500 pixels wide by 500 pixels tall that can be resized. The 'logical' graphics area stretches from -200 to 200 in both directions. In this window there is a triangle that will bounce back and forth across the window, changing direction when it hits the side of the window, or when you press the spacebar.

For your program you will replace the triangle with a rectangular paddle and a square ball within this same space. The user will move the paddle around the screen using the i/j/k/l keys moving up/left/down/right respectively. The edge of the paddle should stop at the edge of the screen - so the entire paddle should always remain visible on the screen. The ball will move about the window, bouncing off the sides of the window and bouncing off the sides (top, left, right, bottom) of the paddle - the entire ball should also always remain visible on the screen. The motion of the ball is fairly simple - the ball will keep a constant horizontal and vertical speed, but its direction will change appropriately when it hits an obstacle (i.e. if the ball hits a vertical surface then its horizontal velocity should change sign, if it hits a horizontal surface then its vertical velocity will change sign.)

The center of the ball will start out at logical coordinates 0,0 (the center of the window). The center of the paddle will start out at logical coordinates 0, -150. The ball will initially be moving in a random direction. The speed of the ball is up to you. It should be fast enough to be interesting, but not so fast that you cant hit it with the paddle.

The program should accept a set of command line parameters. If these values are not changed via the command line then the program should use the built in defaults:

Your program should be well commented and be a good example of literate programming.

Your program will be submitted electronically. This will be discussed further in the discussion section. You can compile your program using the OpenGL libraries or any of the implementations of the Mesa libraries, but be sure that it compiles and runs on the SGI O2s in the CS lab because that is where we will be compiling and running your program.

The biggest problem you will encounter is the dreaded 'black screen' - its hard to debug graphics code when you can't see any graphics on the screen. The code to draw the triangle should help you over this hurdle, but I would first get the code to draw the paddle and ball on the screen, then add the ability to move the paddle, then the movement of the ball, then the bouncing of the ball.

I would also highly recommend that you understand the code you are writing - you never know when you might need to reproduce it (hint hint).