CS 488: Assignment 4
Due: 4/29/03 at 2:00pm
In this fourth assignment you will enhance the program you wrote in assignment 3 and experiment with some of the more advanced features of OpenGL.
This assignment will be a little different in that I'm hoping its closer to the 'real world.' I'm going to tell you what features the application should have, and some of the commands you will need, but for several of the features you will need to dig into the red OpenGL book and learn by doing.
This enhanced version adds the following to the requirements given in assignment 3:
- You will draw everything with filled polygons rather than just lines. Instead of using with glBegin(GL_LINE_LOOP); you should look at GL_POLYGON.
- You will use smooth shading (rather than flat shading) for all of the polygons with
- You will set up window to have a depth buffer using
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
and enable the Z-buffer with
and at the beginning of each draw cycle you will need to clear the depth buffer as well as the colour buffer with
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
so that occluded polygons are not drawn
- You will turn on back-face culling with
so only the appropriate sides of the polygons show up. Note that when drawing with lines that the order the vertices were specified in did not matter, but here it will matter - with back-face culling turned on the polygons must be drawn in counterclockwise order when seen from their visible side or they won't show up.
- Instead of defining the colour of the lines as in assignment 3, here you will define the material properties of the polygons. This gives you much more control over how objects appear but for this assignment we will only deal with the diffuse colour of each polygon. You will be using glMaterialfv(GL_FRONT, GL_DIFFUSE, <your properties vector>);
- The user's ship is equipped with a light (point light) to illuminate the landscape and the objects on it. That is you will need to define an appropriate white point light source that moves with the user through the scene.
and you will need to define some parameters for the light source itself e.g. its position. The light's position will have a w value of 1
- Since we are using lighting we should also define the normals for each vertex as we define the object using glNormal3f(nx,ny,nz); This means we need some way to define what the normals are - so we are going to modify the data files for the program slightly. In between the number of vertices and the first vertex definition we are going to insert a line giving the vertex for the normal e.g.
0 1 0 <--- new line giving the normal for all of the vertices in this polygon
-2.5 2.5 0
2.5 2.5 0
2.5 2.5 10
-2.5 2.5 10
- You will use fog (in the computer graphics sense) to make objects further away appear darker using glFogi(GL_FOG_MODE, GL_LINEAR);
glFogi(GL_FOG_START, <where it starts close to you>);
glFogi(GL_FOG_END, <where things are completely obscured in the distance>);
- You will map a modulated texture onto the grass (elevations 1 through 5) a different texture onto the water (elevation 0) and a different texture onto the dirt (elevation 6-8) to make the scene look more realistic. You can leave the snow at elevation 9 white.With a modulated texture the lighting will affect the texture making the scene look more realistic than with a decal texture where the light would be ignored. Here you will get to use glTexImage2D to define the texture, glTexParameterf to define how to map the wrap the texture, glTexEnvf to set the texture to be modulated, glEnable to turn on texture mapping and glTexCoord2f to map specific texture coordinates onto specific vertices. You can generate some simple texture maps yourself through code, or you can convert existing textures into images that your program can read in. You can find some textures here: http://www.webpagebackground.com and http://wp.netscape.com/assist/net_sites/bg/backgrounds.html. I'm not saying these are the most appropriate, but its a starting point. To use existing textures such as these you will probably want to convert the texture into raw RGB bytes rather than in some image format such as PNG, TIFF , JPG etc - it makes reading the texture in easier. Photoshop, XV, etc can do this quite easily. You may also want to start with a black and white bitmapped texture, or greyscale texture before moving onto a dull colour image. If you feel motivated you can add more textures for some bonus points.
- Part of the original defender game was rescuing people, so now we are going to add that in as well. There will be five people moving about on the surface. We will constrain these people to always be at height 1. When your program starts up the computer will place each of these five people onto the center of a random piece of ground which is at elevation 1 that does not already contain a cube or pyramid or another person. This means that your landscape should have at least 5 patches of ground at elevation 1, and you can assume all landscapes given as input to the program will have at least 5 patches at elevation 1. You should come up with some nice representation for this person, using the same object format file as for the cubes and pyramids. Your 'goal' in this new version is to find and rescue these people. If your craft flies into one of these people then you rescue them and they disappear from the surface - that is your ship is over the center of the patch they are in, at a height very close to the elevation of the patch.
- You will give the user the ability to switch from their first-person view to a map view (top down view) of the landscape centered on their current position. The map should contain some nice representation of the user's craft at that spot. The map should also show where the people you are rescuing are located. The user can still navigate and the map should update appropriately. That is, the user can still play the game in map mode. The user should also be able to zoom in and out in this view.
- A textual display will show how many people you have rescued, and your current position, elevation, and heading over the landscape.
- You will use the SGI-specific sound routines to make your program a little more interesting by have some sounds triggered on various events. The simplest way to do this is to have the system execute 'sfplay <soundfile> &' when an appropriate event occurs. This doesnt work for 'atmospheric' background sounds but works well enough for sounds triggered by events. You can find some sample sound files at http://www.partnersinrhyme.com/contents/contentssfx.html. Again I'm not endorsing these sounds, just giving a pointer. Soundeditor on the O2s can be used to convert file formats. Hint - you should probably have all of your sounds at the same sampling rate.
- You should design an interesting landscape for the user to fly around.
- Create a new Tree object represented by a 'T' in the objects.txt file.
- Some of the features added here require hardware acceleration to work at interactive speeds. For modern graphics cards (within the last year or two) they should not be a problem. For older machines (like the O2s) it might be. You should allow the user to interactively turn on/off the textures, the light, and the fog. The game should still look good and be playable without the textures and fog.
Note that this writeup is intentionally not giving you all the details on how to go about doing all of these various things. There are several nice links on the web pages to the man pages for the various OpenGL functions, and the Red Book online, and sample code so you should do some research before you start coding on how to apply the various routines. The basic goal here is to come up with a game that is visually interesting while still being quite playable on the O2s.
Also note that while creativity is encouraged on this assignment that does not mean that you should grab textures and sounds from published sources without their permission. Creating your own textures and sounds is highly encouraged, and using public domain images and sounds are fine as long as you cite the source.
As usual your program should be well commented and be a good example of literate programming. As usual your program will be submitted electronically and you need to be sure that it compiles and runs on the SGI O2s in the CS lab. And again as usual 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).