CSE581 Lab 4 (15 points)
Due: December 1st,
Friday 11:59pm
Objectives:
1. (4 pts) Add OpenGL textures to your scene:
a Choose an appropriate image and map it to the floor
b. Map at least one other texture somewhere in the scene
wherever makes sense.
c. Use key stroke 't' to turn
on/off the textures
3. (2 pt) Allow two different camera positions to
view your scene.Use key stroke 'v' to switch
between the two views.
3. (3 pts) Create a picture-in-picture effect. Pick an additional
camera for the scene and render the scene using that camera into a small window
at the upper left corner of your display window. If this camera is the first
person view from your main object, you get an extra credit..
Use key ‘p’ to toggle this effect.
4. (3 pts) Add a semi-transparent object to the
scene. To do this you need to use OpenGL's alpha blending feature. In essence,
you need to enable OpenGL blending by calling the function glEnable(GL_BLEND),
and set up the blending function using glBlendFunc().
The parameter in this function should be GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALHPA.
Also, you need to use glColor4f() with
the last parameter as the opacity (range: [0-1]; 1: opaque; 0: transparent)
This semi-transparent object should be the last object to draw in your display
function. Read the description in the red book.
5. (3 pts) Finally, allow the program to output
the image to a file by pressing the key stroke 'o'. To do this, you need
to read the frame buffer back to memory by using the function glReadPixels(). For instance, calling glReadPixels(0, 0, ScreenWidth, ScreenHeight,
GL_RGB, GL_UNSIGNED_BYTE, Image) will dump the frame buffer (RGB pixels) to an
array named 'Image' in your memory which is declared by you and has dimensions ScreenWidth*ScreenHeight*3 with
the type as unsigned character. Output the memory content to a ppm file. Below is a pseudo code of writing out ppm files.
FILE *fp;
fp = fopen("out.ppm","w");
int
height = ScreenHeight; // you need to know this from
somewhere else
int
width = ScreenWidth; // same here.
int max_ccv = 255; // Write
the 'header' information
fprintf(fp,"P3
%d %d %d\n", width, height, max_ccv);
for each row, for each pixel,
write out integer value from 0 to255 for each of R, G, B
fclose(fp);
Best Graphics Competition: Submit your image(s)/animation(s) to compete for the best images or animations! Whoever participate this will get one extra credit for the lab. The 1st place will get 3 bonus points, and the 2nd place will earn 2 points. . If you wish to participate, create a web page and post your images/animations there before our Dec. 1st (Friday) class. You will show your work to the class on Friday and we will vote for the winners.