Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/levelloader/src/lib/graphics/graphics_engine.cc @ 4225

Last change on this file since 4225 was 3746, checked in by chris, 20 years ago

orxonox/branches/levelloader: Merged trunk into branch… still not working though…

File size: 4.9 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
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
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GRAPHICS
17
18#include "graphics_engine.h"
19
20#include "debug.h"
21
22using namespace std;
23
24
25/**
26   \brief standard constructor
27   \todo this constructor is not jet implemented - do it
28*/
29GraphicsEngine::GraphicsEngine () 
30{
31  this->setClassName ("GraphicsEngine");
32  this->initVideo();
33
34  this->listModes();
35}
36
37/**
38   \brief The Pointer to this GraphicsEngine
39*/
40GraphicsEngine* GraphicsEngine::singletonRef = NULL;
41
42/**
43   \returns A pointer to this GraphicsEngine
44*/
45GraphicsEngine* GraphicsEngine::getInstance()
46{
47  if (!GraphicsEngine::singletonRef)
48    GraphicsEngine::singletonRef = new GraphicsEngine();
49  return GraphicsEngine::singletonRef;
50}
51
52
53/**
54   \brief destructs the graphicsEngine.
55*/
56GraphicsEngine::~GraphicsEngine () 
57{
58  // delete what has to be deleted here
59}
60
61/**
62   \brief initializes the Video for openGL.
63
64   This has to be done only once when starting orxonox.
65*/
66int GraphicsEngine::initVideo()
67{
68  // initialize SDL_VIDEO
69  if (SDL_Init(SDL_INIT_VIDEO) == -1)
70    {
71      PRINTF(1)("could not initialize SDL Video\n");
72      //      return -1;
73    }
74  // initialize SDL_GL-settings
75  this->setGLattribs();
76
77  // setting the Video Flags.
78  this->videoFlags = SDL_OPENGL | SDL_HWPALETTE | SDL_RESIZABLE | SDL_DOUBLEBUF;
79
80  /* query SDL for information about our video hardware */
81  const SDL_VideoInfo* videoInfo = SDL_GetVideoInfo ();
82  if( videoInfo == NULL)
83    {
84      PRINTF(1)("Failed getting Video Info :%s\n", SDL_GetError()); 
85      SDL_Quit ();
86    }
87  if( videoInfo->hw_available)
88    this->videoFlags |= SDL_HWSURFACE;
89  else 
90    this->videoFlags |= SDL_SWSURFACE;
91  /*
92  if(VideoInfo -> blit_hw)
93    VideoFlags |= SDL_HWACCEL;
94  */
95
96  // setting up the Resolution
97  this->setResolution(800, 600, 16);
98 
99  // Set window labeling
100  SDL_WM_SetCaption ("Orxonox " PACKAGE_VERSION, "Orxonox " PACKAGE_VERSION);
101 
102  // TO DO: Create a cool icon and use it here
103  SDL_WM_SetIcon(SDL_LoadBMP("../data/pictures/orxonox-icon32x32.bmp"), NULL); 
104
105  // Enable default GL stuff
106  glEnable(GL_DEPTH_TEST);
107}
108
109/**
110   \brief Sets the GL-attributes
111*/
112int GraphicsEngine::setGLattribs(void)
113{
114  // Set video mode
115  // TO DO: parse arguments for settings
116  //SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
117  //SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
118  //SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
119  //SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
120 
121
122  SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );   
123  SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16);   
124  SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, 0); 
125  SDL_GL_SetAttribute( SDL_GL_ACCUM_RED_SIZE, 0);
126  SDL_GL_SetAttribute( SDL_GL_ACCUM_GREEN_SIZE, 0);
127  SDL_GL_SetAttribute( SDL_GL_ACCUM_BLUE_SIZE, 0);
128  SDL_GL_SetAttribute( SDL_GL_ACCUM_ALPHA_SIZE, 0);
129}
130
131/**
132   \brief sets the Resolution of the Screen to display the Graphics to.
133   \param width The width of the window
134   \param height The height of the window
135   \param bpp bits per pixel
136*/
137int GraphicsEngine::setResolution(int width, int height, int bpp)
138{
139  this->resolutionX = width;
140  this->resolutionY = height;
141  this->bitsPerPixel = bpp;
142 
143  printf ("ok\n");
144  if((this->screen = SDL_SetVideoMode(this->resolutionX, this->resolutionY, this->bitsPerPixel, this->videoFlags)) == NULL)
145    {
146      PRINTF(1)("Could not SDL_SetVideoMode(%d, %d, %d, %d): %s\n", this->resolutionX, this->resolutionY, this->bitsPerPixel, this->videoFlags, SDL_GetError());
147      SDL_Quit();
148      //    return -1;
149    }
150
151}
152
153/**
154   \brief Signalhandler, for when the resolution has changed
155   \param resizeInfo SDL information about the size of the new screen size
156*/
157int GraphicsEngine::resolutionChanged(SDL_ResizeEvent* resizeInfo)
158{
159  this->setResolution(resizeInfo->w, resizeInfo->h, this->bitsPerPixel);
160}
161
162/**
163   \brief if Textures should be enabled
164*/
165bool GraphicsEngine::texturesEnabled = true;
166
167
168
169
170
171
172
173/**
174   \brief outputs all the Fullscreen modes.
175*/
176void GraphicsEngine::listModes(void)
177{
178  /* Get available fullscreen/hardware modes */
179  this->videoModes=SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_HWSURFACE);
180 
181  /* Check is there are any modes available */
182  if(this->videoModes == (SDL_Rect **)0){
183    PRINTF(1)("No modes available!\n");
184    exit(-1);
185  }
186 
187  /* Check if our resolution is restricted */
188  if(this->videoModes == (SDL_Rect **)-1){
189    PRINTF(1)("All resolutions available.\n");
190  }
191  else{
192    /* Print valid modes */
193    PRINT(0)("Available Resoulution Modes are\n");
194    for(int i = 0; this->videoModes[i]; ++i)
195      PRINT(0)(" |  %d x %d\n", this->videoModes[i]->w, this->videoModes[i]->h);
196  }
197 
198}
Note: See TracBrowser for help on using the repository browser.