CMPS-3480 Computer Graphics
Lab-6
Overview:
The code we wrote in class is on Odin at: /home/fac/gordon/p/3480/code/lab6/in_class_opengl.cpp Start with your opengl.cpp program. Follow along in lab class. Save your opengl.cpp and Makefile to Odin 3480/6/ folder. You must save your lab work out to Odin folder 6.
Item #1 Animate your rocket ship on key-press A. Here is my own animation created after class. Source code to make your own animated gif... //The Imagemagick command: //convert -loop 0 -coalesce -layers OptimizeFrame -delay 10 img*.ppm abc.gif //Put it inside a system command maybe like this... char str[] = "convert -loop 0 -coalesce -layers OptimizeFrame -delay 10 img*.ppm abc.gif"; system(str); //Call the system command just once after your animation has been turned off! //Here is a function to capture your window and save to an image. //You should designate another key-press such as 'B' to create the gif. //Leave your key-press 'A' just to look at the animation. // //This function takes a snapshot of your current window. //To create an animation, many snapshots must be taken. //Setup a counter that increments each frame. //Call the screen capture every n frames. Try 10-frames or 6-frames maybe. // //The key-press that starts the animation should also turn it off when pressed //again. This way you can turn off the animation so as not to create a million //images and fill up your disk or Odin account. // //Once your series of images is created, you can use convert as described. //You can also bring the images into Gimp and create a gif animation. void screen_capture() { //screen shot, capture, snapshot, opengl screenshot static int inc = 0; int xres = g.xres; int yres = g.yres; //get pixels unsigned char *data = new unsigned char [xres * yres * 3]; glReadPixels(0, 0, xres, yres, GL_RGB, GL_UNSIGNED_BYTE, data); //write ppm file... char ts[256]; sprintf(ts, "img%03i.ppm", inc++); FILE *fpo = fopen(ts, "w"); fprintf(fpo, "P6\n"); fprintf(fpo, "%i %i\n", xres, yres); fprintf(fpo, "255\n"); //go backwards a row at a time... unsigned char *p = data; p = p + ((yres-1) * xres * 3); unsigned char *start = p; for (int i=0; i<yres; i++) { for (int j=0; j<xres*3; j++) { fprintf(fpo, "%c", *p); ++p; } start = start - (xres*3); p = start; } fclose(fpo); }
Create a web page on Odin at: public_html/3480/index.html NOT x3480! On the page... 1. Give the title of your semester project. 2. Post a small image with a hint of what your project output might look like. 3. Post your OpenGL lab-6 animation.
Your instructor will find your work out on Odin!