1 | |
---|
2 | |
---|
3 | #include "windowHandler.h" |
---|
4 | #include <stdio.h> |
---|
5 | void WindowHandler::ReSizeGLScene(GLsizei width, GLsizei height) // Resize And Initialize The GL Window |
---|
6 | { |
---|
7 | if (height==0) // Prevent A Divide By Zero By |
---|
8 | { |
---|
9 | height=1; // Making Height Equal One |
---|
10 | } |
---|
11 | |
---|
12 | glViewport(0,0,width,height); // Reset The Current Viewport |
---|
13 | |
---|
14 | |
---|
15 | glMatrixMode(GL_PROJECTION); // Select The Projection Matrix |
---|
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 | |
---|
23 | glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix |
---|
24 | glLoadIdentity(); // Reset The Modelview Matrix |
---|
25 | |
---|
26 | } |
---|
27 | |
---|
28 | |
---|
29 | int WindowHandler::InitGL(GLvoid) // All Setup For OpenGL Goes Here |
---|
30 | { |
---|
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 |
---|
38 | |
---|
39 | return TRUE; |
---|
40 | } |
---|
41 | |
---|
42 | |
---|
43 | GLvoid WindowHandler::KillGLWindow(GLvoid) // Properly Kill The Window |
---|
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 ); |
---|
65 | if ( SDL_SetVideoMode(width, height, 0, flags) == NULL ) { |
---|
66 | return FALSE; |
---|
67 | } |
---|
68 | SDL_GL_GetAttribute( SDL_GL_STENCIL_SIZE, &size); |
---|
69 | |
---|
70 | ReSizeGLScene(width, height); // Set Up Our Perspective GL Screen |
---|
71 | |
---|
72 | if (!InitGL()) // Initialize Our Newly Created GL Window |
---|
73 | { |
---|
74 | KillGLWindow(); // Reset The Display |
---|
75 | return FALSE; // Return FALSE |
---|
76 | } |
---|
77 | |
---|
78 | return TRUE; // Success |
---|
79 | } |
---|
80 | |
---|
81 | |
---|