Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/osX/importer/windowHandler.cc @ 2978

Last change on this file since 2978 was 2977, checked in by bensch, 20 years ago

orxonox/branches/importer: merged back from the trunk again: command: svn merge trunk/ branches/osX -r 2887:HEAD

File size: 2.0 KB
RevLine 
[2748]1
2
3#include "windowHandler.h"
4#include <stdio.h>
[2977]5void WindowHandler::ReSizeGLScene(GLsizei width, GLsizei height) // Resize And Initialize The GL Window
[2748]6{
[2977]7        if (height==0)  // Prevent A Divide By Zero By
[2748]8        {
[2977]9                height=1;// Making Height Equal One
[2748]10        }
11
[2977]12        glViewport(0,0,width,height); // Reset The Current Viewport
[2748]13
[2977]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
[2977]23        glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
24        glLoadIdentity(); // Reset The Modelview Matrix
[2748]25
26}
27
28
29int WindowHandler::InitGL(GLvoid)                                                                               // All Setup For OpenGL Goes Here
30{
[2977]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
[2977]43GLvoid WindowHandler::KillGLWindow(GLvoid) // Properly Kill The Window
[2748]44{
45        SDL_Quit();
46}
47
48
49BOOL 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 );
[2977]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
[2977]70        ReSizeGLScene(width, height); // Set Up Our Perspective GL Screen
[2748]71
[2977]72        if (!InitGL()) // Initialize Our Newly Created GL Window
[2748]73        {
[2977]74          KillGLWindow();  // Reset The Display
75          return FALSE;
[2748]76        }
77
[2977]78        return TRUE;
[2748]79}
80
81
Note: See TracBrowser for help on using the repository browser.