#include "framework.h" int verbose = 1; void DrawGLScene() { rotatorP += rotatorV; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glLoadIdentity(); // Reset the view glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f,500/375,0.1f,dist * 5.0f); gluLookAt (dist*sin(rotatorP),dist ,dist*cos(rotatorP), 0,0,0, 0,1,0); obj->draw(); SDL_GL_SwapBuffers(); // Swap the buffers } int main(int argc, char *argv[]) { Uint8* keys; // This variable will be used in the keyboard routine int done=FALSE; // We aren't done yet, are we? // Create a new OpenGL window with the title "Cone3D Basecode" at // 640x480x32, fullscreen and check for errors along the way if(wHandler.CreateGLWindow("Whandler Basecode", 500, 375, 32, FALSE) == FALSE) { // If an error is found, display a message, kill the GL and SDL screens (if they were created) and exit printf("Could not initalize OpenGL :(\n\n"); wHandler.KillGLWindow(); return 0; } printf ("%i, %i\n", wHandler.screen->w, wHandler.screen->h); if (argc>=3) obj = new Object (argv[1], atof(argv[2])); else if (argc>=2) obj = new Object(argv[1]); else obj = new Object(); glEnable(GL_LIGHTING); glEnable(GL_DEPTH_TEST); GLfloat whiteLight[] = {1.0, 1.0, 1.0,1.0}; GLfloat light0Position[] = {10.0, 10.0, 10.0, 0.0}; GLfloat light1Position[] = {-10.0, -7.0, -6.0, 0.0}; GLfloat lmodelAmbient[] = {.1, .1, .1, 1.0}; glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0, GL_POSITION, light0Position); glLightfv(GL_LIGHT0, GL_DIFFUSE, whiteLight); glLightfv(GL_LIGHT0, GL_SPECULAR, whiteLight); glEnable(GL_LIGHT1); glLightfv(GL_LIGHT1, GL_POSITION, light1Position); glLightfv(GL_LIGHT1, GL_DIFFUSE, whiteLight); glLightfv(GL_LIGHT1, GL_SPECULAR, whiteLight); rotatorP = .0; rotatorV = .0; dist = 5.0; // Build the font from a TGA image font.tga in the data directory // Hide the mouse cursor SDL_ShowCursor(2); // This is the main loop for the entire program and it will run until done==TRUE while(!done) { // Draw the scene DrawGLScene(); // And poll for events SDL_Event event; while ( SDL_PollEvent(&event) ) { switch (event.type) { case SDL_MOUSEMOTION: if (verbose >=3) printf("Mouse motion about %d,%d Pixels to (%d,%d).\n", event.motion.xrel, event.motion.yrel, event.motion.x, event.motion.y); break; case SDL_MOUSEBUTTONDOWN: if (event.button.button == 4) { printf("MouseWheel up\n"); dist *= .5; } else if (event.button.button == 5) { printf("MouseWheel down\n"); dist *= 2; } else { printf("MouseButton %d pressed at (%d,%d).\n", event.button.button, event.button.x, event.button.y); rotatorV = ( (float)wHandler.screen->w/2 -event.button.x) / (float)wHandler.screen->w / 100.0; } break; /* case SDL_MOUSEBUTTONUP: printf("MouseButton %d released at (%d,%d).\n", event.button.button, event.button.x, event.button.y); break; */ // If a quit event was recieved case SDL_QUIT: // then we're done and we'll end this program done=TRUE; break; default: break; } } // Get the state of the keyboard keys keys = SDL_GetKeyState(NULL); // and check if ESCAPE has been pressed. If so then quit if(keys[SDLK_ESCAPE]) done=TRUE; } // Kill the GL & SDL screens delete obj; wHandler.KillGLWindow(); // And quit return 0; }