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