| [3140] | 1 | /*  | 
|---|
 | 2 |    orxonox - the future of 3D-vertical-scrollers | 
|---|
| [2748] | 3 |  | 
|---|
| [3140] | 4 |    Copyright (C) 2004 orx | 
|---|
| [2748] | 5 |  | 
|---|
| [3140] | 6 |    This program is free software; you can redistribute it and/or modify | 
|---|
 | 7 |    it under the terms of the GNU General Public License as published by | 
|---|
 | 8 |    the Free Software Foundation; either version 2, or (at your option) | 
|---|
 | 9 |    any later version. | 
|---|
 | 10 |  | 
|---|
 | 11 |    ### File Specific: | 
|---|
 | 12 |    main-programmer: Benjamin Grauer | 
|---|
 | 13 |    co-programmer: ... | 
|---|
 | 14 | */ | 
|---|
 | 15 |  | 
|---|
| [2748] | 16 | #include "windowHandler.h" | 
|---|
 | 17 | #include <stdio.h> | 
|---|
| [3454] | 18 |  | 
|---|
 | 19 | /** | 
|---|
 | 20 |    \brief Resizes the Window | 
|---|
 | 21 |    \param width the new size in the width. | 
|---|
 | 22 |    \param height the new size in the height. | 
|---|
 | 23 | */ | 
|---|
| [2931] | 24 | void WindowHandler::ReSizeGLScene(GLsizei width, GLsizei height) // Resize And Initialize The GL Window | 
|---|
| [2748] | 25 | { | 
|---|
| [2931] | 26 |         if (height==0)  // Prevent A Divide By Zero By | 
|---|
| [2748] | 27 |         { | 
|---|
| [2931] | 28 |                 height=1;// Making Height Equal One | 
|---|
| [2748] | 29 |         } | 
|---|
 | 30 |  | 
|---|
| [2931] | 31 |         glViewport(0,0,width,height); // Reset The Current Viewport | 
|---|
| [2748] | 32 |  | 
|---|
| [2931] | 33 |          | 
|---|
 | 34 |         glMatrixMode(GL_PROJECTION); // Select The Projection Matrix | 
|---|
| [2748] | 35 |         glLoadIdentity();        | 
|---|
 | 36 |  | 
|---|
 | 37 |  | 
|---|
 | 38 |         // Calculate The Aspect Ratio Of The Window | 
|---|
 | 39 |         gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f); | 
|---|
 | 40 |         gluLookAt (0,0,15, 0,0,0, 0,1,0); | 
|---|
 | 41 |  | 
|---|
| [2931] | 42 |         glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix | 
|---|
 | 43 |         glLoadIdentity(); // Reset The Modelview Matrix | 
|---|
| [2748] | 44 |  | 
|---|
 | 45 | } | 
|---|
 | 46 |  | 
|---|
| [3454] | 47 | /** | 
|---|
 | 48 |    \brief initializes openGL | 
|---|
 | 49 | */ | 
|---|
| [2748] | 50 | int WindowHandler::InitGL(GLvoid)                                                                               // All Setup For OpenGL Goes Here | 
|---|
 | 51 | { | 
|---|
| [2931] | 52 |         glEnable(GL_TEXTURE_2D); // Enable Texture Mapping | 
|---|
 | 53 |         glShadeModel(GL_SMOOTH); // Enable Smooth Shading | 
|---|
 | 54 |         glClearColor(0.00f, 0.00f, 0.00f, 0.0f); // Black Background | 
|---|
 | 55 |         glClearDepth(1.0f);  // Depth Buffer Setup | 
|---|
 | 56 |         glEnable(GL_DEPTH_TEST); // Enables Depth Testing | 
|---|
 | 57 |         glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do | 
|---|
 | 58 |         glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);  // Really Nice Perspective Calculations | 
|---|
| [2748] | 59 |  | 
|---|
 | 60 |     return TRUE; | 
|---|
 | 61 | } | 
|---|
 | 62 |  | 
|---|
| [3454] | 63 | /** | 
|---|
 | 64 |    \brief kills the window | 
|---|
 | 65 | */ | 
|---|
| [2931] | 66 | GLvoid WindowHandler::KillGLWindow(GLvoid) // Properly Kill The Window | 
|---|
| [2748] | 67 | { | 
|---|
 | 68 |         SDL_Quit(); | 
|---|
 | 69 | } | 
|---|
 | 70 |  | 
|---|
| [3454] | 71 | /** | 
|---|
 | 72 |    \brief creates a new Window for the scene | 
|---|
 | 73 |    \param title the name of the Window | 
|---|
 | 74 |    \param width the width of the window | 
|---|
 | 75 |    \param height the height of the window | 
|---|
 | 76 |    \param bits the bits per pixel to use | 
|---|
 | 77 |    \param fullscreenflag TRUE if fullscreen FALSE if windowed/ | 
|---|
 | 78 |    \returns FALSE if initialisation failed, TRUE otherwise | 
|---|
 | 79 | */ | 
|---|
| [2748] | 80 | BOOL WindowHandler::CreateGLWindow(char* title, int width, int height, int bits, BOOL fullscreenflag) | 
|---|
 | 81 | { | 
|---|
 | 82 |         Uint32 flags; | 
|---|
 | 83 |         int size; | 
|---|
 | 84 |  | 
|---|
 | 85 |         /* Initialize SDL */ | 
|---|
 | 86 |         if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { | 
|---|
 | 87 |                 fprintf(stderr, "Couldn't init SDL: %s\n", SDL_GetError()); | 
|---|
 | 88 |                 return FALSE; | 
|---|
 | 89 |         } | 
|---|
 | 90 |  | 
|---|
 | 91 |         flags = SDL_OPENGL; | 
|---|
 | 92 |         if ( fullscreenflag ) { | 
|---|
 | 93 |                 flags |= SDL_FULLSCREEN; | 
|---|
 | 94 |         } | 
|---|
 | 95 |         SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, 1 ); | 
|---|
| [2936] | 96 |         if ( (screen = SDL_SetVideoMode(width, height, 0, flags)) == NULL ) { | 
|---|
| [2748] | 97 |                 return FALSE; | 
|---|
 | 98 |         } | 
|---|
 | 99 |         SDL_GL_GetAttribute( SDL_GL_STENCIL_SIZE, &size); | 
|---|
 | 100 |  | 
|---|
| [2931] | 101 |         ReSizeGLScene(width, height); // Set Up Our Perspective GL Screen | 
|---|
| [2748] | 102 |  | 
|---|
| [2931] | 103 |         if (!InitGL()) // Initialize Our Newly Created GL Window | 
|---|
| [2748] | 104 |         { | 
|---|
| [2931] | 105 |           KillGLWindow();  // Reset The Display | 
|---|
 | 106 |           return FALSE; | 
|---|
| [2748] | 107 |         } | 
|---|
 | 108 |  | 
|---|
| [2931] | 109 |         return TRUE; | 
|---|
| [2748] | 110 | } | 
|---|
 | 111 |  | 
|---|
 | 112 |  | 
|---|