| [2748] | 1 |  | 
|---|
 | 2 |  | 
|---|
 | 3 | #include "windowHandler.h" | 
|---|
 | 4 | #include <stdio.h> | 
|---|
| [2931] | 5 | void WindowHandler::ReSizeGLScene(GLsizei width, GLsizei height) // Resize And Initialize The GL Window | 
|---|
| [2748] | 6 | { | 
|---|
| [2931] | 7 |         if (height==0)  // Prevent A Divide By Zero By | 
|---|
| [2748] | 8 |         { | 
|---|
| [2931] | 9 |                 height=1;// Making Height Equal One | 
|---|
| [2748] | 10 |         } | 
|---|
 | 11 |  | 
|---|
| [2931] | 12 |         glViewport(0,0,width,height); // Reset The Current Viewport | 
|---|
| [2748] | 13 |  | 
|---|
| [2931] | 14 |          | 
|---|
 | 15 |         glMatrixMode(GL_PROJECTION); // Select The Projection Matrix | 
|---|
| [2748] | 16 |         glLoadIdentity();        | 
|---|
 | 17 |  | 
|---|
 | 18 |  | 
|---|
 | 19 |         // Calculate The Aspect Ratio Of The Window | 
|---|
 | 20 |         gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f); | 
|---|
 | 21 |         gluLookAt (0,0,15, 0,0,0, 0,1,0); | 
|---|
 | 22 |  | 
|---|
| [2931] | 23 |         glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix | 
|---|
 | 24 |         glLoadIdentity(); // Reset The Modelview Matrix | 
|---|
| [2748] | 25 |  | 
|---|
 | 26 | } | 
|---|
 | 27 |  | 
|---|
 | 28 |  | 
|---|
 | 29 | int WindowHandler::InitGL(GLvoid)                                                                               // All Setup For OpenGL Goes Here | 
|---|
 | 30 | { | 
|---|
| [2931] | 31 |         glEnable(GL_TEXTURE_2D); // Enable Texture Mapping | 
|---|
 | 32 |         glShadeModel(GL_SMOOTH); // Enable Smooth Shading | 
|---|
 | 33 |         glClearColor(0.00f, 0.00f, 0.00f, 0.0f); // Black Background | 
|---|
 | 34 |         glClearDepth(1.0f);  // Depth Buffer Setup | 
|---|
 | 35 |         glEnable(GL_DEPTH_TEST); // Enables Depth Testing | 
|---|
 | 36 |         glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do | 
|---|
 | 37 |         glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);  // Really Nice Perspective Calculations | 
|---|
| [2748] | 38 |  | 
|---|
 | 39 |     return TRUE; | 
|---|
 | 40 | } | 
|---|
 | 41 |  | 
|---|
 | 42 |  | 
|---|
| [2931] | 43 | GLvoid WindowHandler::KillGLWindow(GLvoid) // Properly Kill The Window | 
|---|
| [2748] | 44 | { | 
|---|
 | 45 |         SDL_Quit(); | 
|---|
 | 46 | } | 
|---|
 | 47 |  | 
|---|
 | 48 |  | 
|---|
 | 49 | BOOL WindowHandler::CreateGLWindow(char* title, int width, int height, int bits, BOOL fullscreenflag) | 
|---|
 | 50 | { | 
|---|
 | 51 |         Uint32 flags; | 
|---|
 | 52 |         int size; | 
|---|
 | 53 |  | 
|---|
 | 54 |         /* Initialize SDL */ | 
|---|
 | 55 |         if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { | 
|---|
 | 56 |                 fprintf(stderr, "Couldn't init SDL: %s\n", SDL_GetError()); | 
|---|
 | 57 |                 return FALSE; | 
|---|
 | 58 |         } | 
|---|
 | 59 |  | 
|---|
 | 60 |         flags = SDL_OPENGL; | 
|---|
 | 61 |         if ( fullscreenflag ) { | 
|---|
 | 62 |                 flags |= SDL_FULLSCREEN; | 
|---|
 | 63 |         } | 
|---|
 | 64 |         SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, 1 ); | 
|---|
| [2936] | 65 |         if ( (screen = SDL_SetVideoMode(width, height, 0, flags)) == NULL ) { | 
|---|
| [2748] | 66 |                 return FALSE; | 
|---|
 | 67 |         } | 
|---|
 | 68 |         SDL_GL_GetAttribute( SDL_GL_STENCIL_SIZE, &size); | 
|---|
 | 69 |  | 
|---|
| [2931] | 70 |         ReSizeGLScene(width, height); // Set Up Our Perspective GL Screen | 
|---|
| [2748] | 71 |  | 
|---|
| [2931] | 72 |         if (!InitGL()) // Initialize Our Newly Created GL Window | 
|---|
| [2748] | 73 |         { | 
|---|
| [2931] | 74 |           KillGLWindow();  // Reset The Display | 
|---|
 | 75 |           return FALSE; | 
|---|
| [2748] | 76 |         } | 
|---|
 | 77 |  | 
|---|
| [2931] | 78 |         return TRUE; | 
|---|
| [2748] | 79 | } | 
|---|
 | 80 |  | 
|---|
 | 81 |  | 
|---|