# CMSC 435/634: Introduction to Computer Graphics

## Due September 30, 2004

### The Assignment

For this assignment, you will be using OpenGL to create a simple interactive view of a procedurally modeled scene. There is a sample OpenGL application in your Assn2 directory that you can use as a staring point. You will create a fractal landscape using a sum of noise functions. The landscape itself should be rendered as triangles in a height field; each vertex having a unique x,y, with z provided by the fractal function. Use a sum of octaves of the provided 3D Perlin noise function to create your fractal height — you should only need 2D Perlin noise, use the third dimension to select between random landscapes. Compute everything you need to render once, when you generate your landscape. During your rendering loop, you should only be responding to user interaction and rendering using pre-computed data.

The landscape should be lit by one OpenGL distant light (simulating the sun or moon), and one ambient light (simulating bounce light and atmospheric scattering). For the lighting to work, you will need to compute surface normals at each vertex of your model. Compute these when you initially compute the landscape. The vertex normal should be the average of the normals for each face touching the vertex. Each face normal can be computed using the cross product of two of the edges on that face. Be careful to make sure your normals point up.

For user interaction, your program should support rotation exactly as shown in the sample program. To match rotations to mouse motion on the screen, it adds a rotation around an axis perpendicular to the mouse motion in screen space, before the current transform. You should also respond to several key presses. When space is pressed, you should generate a new random landscape with a different z offset in the noise function. For '+' and '-', you should increase / decrease the number of triangles by a factor of two, and simultaneously increase / decrease the octaves of noise by one. When any of '1' to '5' are pressed, you should select a set of pre-chosen values for z offset, +/- scale, and view that you think look particularly nice.

As always, there will be points for creativity, effort and realism.

### 634 Students

Students registered for the 634 version of the course should make a multifractal landscape, with varying roughness at different points in the landscape. You may choose to vary the roughness based on whatever you like (altitude, slope, color code from an external file, or anything else that comes to mind).

#### Using GLUT

Unfortunately, the only way to pass information between GLUT callback functions (the ones passed to GLUT through the glut*Func() calls) is by using global variables.

If you choose to code in C++, each of the GLUT callback functions must be a top-level function (not a class member function) declared extern "C". For example,

```// declare
extern "C" void draw();

// define
extern "C" void draw() {
// C++ code
}```

### Strategy

There are several ways you could program the procedural mountain. Those details are up to you. I do suggest planning your development with lots of intermediate milestones with visual results. Also, rendering itself can be a great way to debug visually.
• Having trouble getting the fractal function to work out? Display one octave of noise alone as the height.
• Having trouble getting the normals right? Turn off lighting and use the normals to colorize your landscape (using glColor3f for each vertex), remembering, of course, to re-scale to get colors from 0-1.
• If you need to do these a lot, you can add new key handlers to change what you render.
• If you must print or use a debugger, it's much easier if you only print for one or a few selected triangles.

### What to turn in

Turn in this assignment electronically by checking it into your Assn2 CVS directory by 11:59 PM on the day of the deadline. We will use a dated checkout for grading, so you will be graded on whatever has been checked in as of 11:59 PM. Submit a readme.txt file telling us about your assignment. What (if any) help did you receive from books, web sites or people other than the instructor and TA? What did you do to make it look more realistic? For 634 students, what did you use to control your roughness?

Also submit everything we need to run your submission. We should be able to run 'make' in your submission directory on the linux.gl systems to produce a running interactive OpenGL program. Submit your modified Makefile, any C/C++ files, and any other auxiliary files we might need. Be sure to comment your code! You will not be graded on the presence or quality of your comments, but we will look at your code and anything that helps us understand what you did (or were trying to do) can only help. In any case, your programs are expected to be robust and easy to understand.

#### Working at home

Once again, if possible, I urge you to use the university computers for your work. I test things out on the gl systems and may or may not be able to help you if things don't work right for you at home. If you do work at home, your final submitted version must be able to run on the gl machines and must be electronically submitted there.

If you have a X server on your home machine (i.e. if you are running Linux, Mac with X11, or one of the Windows X11 packages), it is possible to run remotely, though interacting with the application is much harder when displaying remotely.

If you absolutely must work at home, you will need:

• An OpenGL library (either from your graphics hardware vendor or Mesa)
• The GLUT library (part of the Mesa demos package or on opengl.org)

All of these libraries are cross-platform and run on both Unix and Windows. However, if there are no pre-built binaries for your platform, you may end up having to build them from the source downloads. Which brings me back to: if you don't have to work at home, don't.