#include #include #include "timer.h" #include "image.h" // function prototypes void display(void); void reshape(int width, int height); void keyboard(unsigned char key, int x, int y); void drawCube(); void init(void); double theta=0; cTimer theTimer; double frameRate=30; const int width=400; const int height=400; Image theImage(width,height); using namespace std; int main(int argc, char **argv) { // set up window glutInitWindowSize(width, height); glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutCreateWindow("Making Movies"); // register callback functions glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(keyboard); glutIdleFunc(display); // initalize opengl parameters init(); // loop until something happens glutMainLoop(); return 0; } void init() { // initialize viewing system glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0, 1.0, 1.0, 100.0); glMatrixMode(GL_MODELVIEW); // initialize shade model to smooth glShadeModel(GL_SMOOTH); // initialize background color to white glClearColor(1.0,1.0,1.0,0.0); // enable depth buffering glEnable(GL_DEPTH_TEST); // create some ambient light float ambient[]={0.5f,.5f,.5f}; glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient); // create a point light float pointLightPosition[]={-1.0f,10.0f,0.0f,1.0f}; float pointLightColor[]={1.0f,1.0f,1.0f,1.0f}; glLightfv(GL_LIGHT0, GL_POSITION, pointLightPosition); glLightfv(GL_LIGHT0, GL_DIFFUSE, pointLightColor); glLightfv(GL_LIGHT0, GL_SPECULAR, pointLightColor); // enable lighting and the point light glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); // set polygon mode glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); // initialize the timer theTimer.startTimer(); } void reshape(int newWidth, int newHeight) { cout << "warning: we are using original width and height for movie!" << endl; glViewport(0,0,width,height); } void display() { char filename[15]="mymovie000.bmp"; static count=0; // initialize modelview matrix glLoadIdentity(); gluLookAt(0.0,3.0,10.0,0.0,0.0,0.0,0.0,1.0,0.0); // clear buffers glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT |GL_STENCIL_BUFFER_BIT); // draw a cube float cubeDiffuse[]={0.0f, 0.0f, 0.8f}; float cubeAmbient[]={0.0f, 0.0f, 0.8f}; glMaterialfv(GL_FRONT, GL_DIFFUSE, cubeDiffuse); glMaterialfv(GL_FRONT, GL_AMBIENT, cubeAmbient); glRotatef(theta,0,1,0); theta+=1; theTimer.endTimer(1.0/frameRate); drawCube(); if (count <10) // create next image { theImage.glReadPixelsWrapper(); filename[9]='0'+count; count++; cout << filename << endl; theImage.writeBMP(filename); } theTimer.startTimer(); glutSwapBuffers(); } void keyboard(unsigned char key, int mouseX, int mouseY) { } void drawCube(void) { glPushMatrix(); glTranslatef(0.0f,0.5f,0.0f); glutSolidCube( 1.0); glPopMatrix(); }