Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/lib/graphics/graphics_engine.cc @ 3617

Last change on this file since 3617 was 3617, checked in by bensch, 19 years ago

orxonox/trunk: little fix to graphicsEngine, now the different resolution-types are outputted. also there is a fix from debug.h all warnings are shown now

File size: 4.1 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
39GraphicsEngine* GraphicsEngine::singletonRef = NULL;
40
41GraphicsEngine* GraphicsEngine::getInstance()
42{
43  if (!GraphicsEngine::singletonRef)
44    GraphicsEngine::singletonRef = new GraphicsEngine();
45  return GraphicsEngine::singletonRef;
46}
47
48
49/**
50   \brief destructs the graphicsEngine.
51*/
52GraphicsEngine::~GraphicsEngine () 
53{
54  // delete what has to be deleted here
55}
56
57/**
58   \brief initializes the Video for openGL.
59
60   This has to be done only once when starting orxonox.
61*/
62int GraphicsEngine::initVideo()
63{
64  // initialize SDL_VIDEO
65  if (SDL_Init(SDL_INIT_VIDEO) == -1)
66    {
67      PRINTF(1)("could not initialize SDL Video\n");
68      //      return -1;
69    }
70  // initialize SDL_GL-settings
71  this->setGLattribs();
72
73  // setting the Video Flags.
74  this->videoFlags = SDL_OPENGL | SDL_HWPALETTE | SDL_RESIZABLE;
75
76  /* query SDL for information about our video hardware */
77  const SDL_VideoInfo* videoInfo = SDL_GetVideoInfo ();
78  if( videoInfo == NULL)
79    {
80      PRINTF(1)("Failed getting Video Info :%s\n", SDL_GetError()); 
81      SDL_Quit ();
82    }
83  if( videoInfo->hw_available)
84    this->videoFlags |= SDL_HWSURFACE;
85  else 
86    this->videoFlags |= SDL_SWSURFACE;
87  /*
88  if(VideoInfo -> blit_hw)                           
89    VideoFlags |= SDL_HWACCEL;
90  */
91
92  // setting up the Resolution
93  this->setResoulution(800, 600, 16);
94 
95  // Set window labeling
96  SDL_WM_SetCaption ("Orxonox " PACKAGE_VERSION, "Orxonox " PACKAGE_VERSION);
97 
98  // TO DO: Create a cool icon and use it here
99  // SDL_WM_SetIcon(SDL_Surface *icon, Uint8 *mask); 
100
101}
102
103
104int GraphicsEngine::setGLattribs(void)
105{
106  // Set video mode
107  // TO DO: parse arguments for settings
108  //SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
109  //SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
110  //SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
111  //SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
112 
113
114  SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );   
115  SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16);   
116  SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, 0); 
117  SDL_GL_SetAttribute( SDL_GL_ACCUM_RED_SIZE, 0);
118  SDL_GL_SetAttribute( SDL_GL_ACCUM_GREEN_SIZE, 0);
119  SDL_GL_SetAttribute( SDL_GL_ACCUM_BLUE_SIZE, 0);
120  SDL_GL_SetAttribute( SDL_GL_ACCUM_ALPHA_SIZE, 0);
121}
122
123int GraphicsEngine::setResoulution(int width, int height, int bpp)
124{
125  this->resolutionX = width;
126  this->resolutionY = height;
127  this->bitsPerPixel = bpp;
128 
129  if((this->screen = SDL_SetVideoMode (this->resolutionX, this->resolutionY, this->bitsPerPixel, this->videoFlags)) == NULL)
130    {
131      PRINTF(1)("Could not SDL_SetVideoMode(%d, %d, %d, %d): %s\n", this->resolutionX, this->resolutionY, this->bitsPerPixel, this->videoFlags, SDL_GetError());
132      SDL_Quit();
133      //    return -1;
134    }
135
136}
137
138
139
140
141
142
143
144/**
145   \brief outputs all the Fullscreen modes.
146*/
147void GraphicsEngine::listModes(void)
148{
149  /* Get available fullscreen/hardware modes */
150  this->videoModes=SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_HWSURFACE);
151 
152  /* Check is there are any modes available */
153  if(this->videoModes == (SDL_Rect **)0){
154    PRINTF(1)("No modes available!\n");
155    exit(-1);
156  }
157 
158  /* Check if our resolution is restricted */
159  if(this->videoModes == (SDL_Rect **)-1){
160    PRINTF(1)("All resolutions available.\n");
161  }
162  else{
163    /* Print valid modes */
164    PRINT(0)("Available Resoulution Modes are\n");
165    for(int i = 0; this->videoModes[i]; ++i)
166      PRINT(0)(" |  %d x %d\n", this->videoModes[i]->w, this->videoModes[i]->h);
167  }
168 
169}
Note: See TracBrowser for help on using the repository browser.