[2748] | 1 | #include "windowHandler.h" // Include the Whandler Basecode |
---|
| 2 | #include "object.h" |
---|
| 3 | |
---|
[2863] | 4 | int verbose = 1; |
---|
[2748] | 5 | WindowHandler wHandler; // Create an instance of the whandler basecode class |
---|
| 6 | Object* obj; |
---|
[2759] | 7 | float rotator = 0.0; |
---|
[2780] | 8 | GLfloat whiteLight[] = {1.0, 1.0, 0.0,1.0}; |
---|
[2748] | 9 | |
---|
| 10 | void DrawGLScene() |
---|
| 11 | { |
---|
[2768] | 12 | rotator +=.001; |
---|
[2759] | 13 | |
---|
[2748] | 14 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
---|
| 15 | glLoadIdentity(); // Reset the view |
---|
| 16 | |
---|
[2794] | 17 | glMatrixMode(GL_PROJECTION); |
---|
[2759] | 18 | glLoadIdentity(); |
---|
| 19 | gluPerspective(45.0f,500/375,0.1f,100.0f); |
---|
[2768] | 20 | gluLookAt (5*sin(rotator),7.5,5*cos(rotator), 0,0,0, 0,1,0); |
---|
[2780] | 21 | whiteLight[1] = .5+.5*sin(rotator*10); |
---|
| 22 | whiteLight[2] = .5+.5*sin(rotator*10); |
---|
[2794] | 23 | |
---|
| 24 | GLfloat lightPosition[] = {10.0*sin(rotator*10), 10, 19.0, 0.0}; |
---|
| 25 | glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); |
---|
| 26 | |
---|
[2780] | 27 | glLightfv(GL_LIGHT0, GL_DIFFUSE, whiteLight); |
---|
[2748] | 28 | obj->draw(); |
---|
| 29 | |
---|
| 30 | SDL_GL_SwapBuffers(); // Swap the buffers |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | int main(int argc, char *argv[]) |
---|
| 35 | { |
---|
| 36 | Uint8* keys; // This variable will be used in the keyboard routine |
---|
| 37 | int done=FALSE; // We aren't done yet, are we? |
---|
| 38 | |
---|
| 39 | // Create a new OpenGL window with the title "Cone3D Basecode" at |
---|
| 40 | // 640x480x32, fullscreen and check for errors along the way |
---|
| 41 | if(wHandler.CreateGLWindow("Whandler Basecode", 500, 375, 32, FALSE) == FALSE) |
---|
| 42 | { |
---|
| 43 | // If an error is found, display a message, kill the GL and SDL screens (if they were created) and exit |
---|
| 44 | printf("Could not initalize OpenGL :(\n\n"); |
---|
| 45 | wHandler.KillGLWindow(); |
---|
| 46 | return 0; |
---|
| 47 | } |
---|
[2846] | 48 | if (argc>=3) |
---|
[2837] | 49 | obj = new Object (argv[1], atof(argv[2])); |
---|
[2846] | 50 | else if (argc>=2) |
---|
[2837] | 51 | obj = new Object(argv[1]); |
---|
[2848] | 52 | else |
---|
| 53 | obj = new Object(); |
---|
[2850] | 54 | |
---|
[2780] | 55 | GLfloat lmodelAmbient[] = {.1, .1, .1, 1.0}; |
---|
| 56 | glLightfv(GL_LIGHT0, GL_DIFFUSE, whiteLight); |
---|
| 57 | glLightfv(GL_LIGHT0, GL_SPECULAR, whiteLight); |
---|
| 58 | glEnable(GL_LIGHTING); |
---|
| 59 | glEnable(GL_LIGHT0); |
---|
| 60 | glEnable(GL_DEPTH_TEST); |
---|
| 61 | |
---|
[2748] | 62 | // Build the font from a TGA image font.tga in the data directory |
---|
| 63 | // Hide the mouse cursor |
---|
| 64 | SDL_ShowCursor(0); |
---|
| 65 | |
---|
| 66 | // This is the main loop for the entire program and it will run until done==TRUE |
---|
| 67 | while(!done) |
---|
| 68 | { |
---|
| 69 | // Draw the scene |
---|
| 70 | DrawGLScene(); |
---|
| 71 | // And poll for events |
---|
| 72 | SDL_Event event; |
---|
| 73 | while ( SDL_PollEvent(&event) ) { |
---|
| 74 | switch (event.type) { |
---|
| 75 | // If a quit event was recieved |
---|
[2863] | 76 | case SDL_QUIT: |
---|
| 77 | // then we're done and we'll end this program |
---|
[2748] | 78 | done=TRUE; |
---|
| 79 | break; |
---|
[2863] | 80 | default: |
---|
[2748] | 81 | break; |
---|
| 82 | } |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | // Get the state of the keyboard keys |
---|
| 86 | keys = SDL_GetKeyState(NULL); |
---|
| 87 | |
---|
| 88 | // and check if ESCAPE has been pressed. If so then quit |
---|
| 89 | if(keys[SDLK_ESCAPE]) done=TRUE; |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | // Kill the GL & SDL screens |
---|
[2848] | 93 | delete obj; |
---|
[2748] | 94 | wHandler.KillGLWindow(); |
---|
| 95 | // And quit |
---|
| 96 | return 0; |
---|
| 97 | } |
---|