Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: small patch to enable/disable textures with one single switch: GraphicsEngine::textureEnabled

File size: 4.9 KB
RevLine 
[1853]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.
[1855]10
11   ### File Specific:
[3610]12   main-programmer: Benjamin Grauer
[1855]13   co-programmer: ...
[1853]14*/
15
[3610]16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GRAPHICS
[1853]17
[3610]18#include "graphics_engine.h"
[1853]19
[3611]20#include "debug.h"
21
[1856]22using namespace std;
[1853]23
[1856]24
[3245]25/**
26   \brief standard constructor
27   \todo this constructor is not jet implemented - do it
28*/
[3610]29GraphicsEngine::GraphicsEngine () 
[3365]30{
[3611]31  this->setClassName ("GraphicsEngine");
32  this->initVideo();
[3610]33
[3617]34  this->listModes();
[3611]35}
[3610]36
[3621]37/**
38   \brief The Pointer to this GraphicsEngine
39*/
[3611]40GraphicsEngine* GraphicsEngine::singletonRef = NULL;
[3610]41
[3621]42/**
43   \returns A pointer to this GraphicsEngine
44*/
[3611]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{
[3617]68  // initialize SDL_VIDEO
[3610]69  if (SDL_Init(SDL_INIT_VIDEO) == -1)
70    {
[3617]71      PRINTF(1)("could not initialize SDL Video\n");
[3610]72      //      return -1;
73    }
[3617]74  // initialize SDL_GL-settings
75  this->setGLattribs();
[3610]76
[3617]77  // setting the Video Flags.
[3619]78  this->videoFlags = SDL_OPENGL | SDL_HWPALETTE | SDL_RESIZABLE | SDL_DOUBLEBUF;
[3610]79
80  /* query SDL for information about our video hardware */
81  const SDL_VideoInfo* videoInfo = SDL_GetVideoInfo ();
82  if( videoInfo == NULL)
83    {
[3617]84      PRINTF(1)("Failed getting Video Info :%s\n", SDL_GetError()); 
[3610]85      SDL_Quit ();
86    }
87  if( videoInfo->hw_available)
[3611]88    this->videoFlags |= SDL_HWSURFACE;
[3610]89  else 
[3611]90    this->videoFlags |= SDL_SWSURFACE;
[3610]91  /*
[3619]92  if(VideoInfo -> blit_hw)
[3610]93    VideoFlags |= SDL_HWACCEL;
94  */
[3611]95
[3617]96  // setting up the Resolution
[3619]97  this->setResolution(800, 600, 16);
[3610]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
[3621]103  SDL_WM_SetIcon(SDL_LoadBMP("../data/pictures/orxonox-icon32x32.bmp"), NULL); 
[3610]104
[3621]105  // Enable default GL stuff
106  glEnable(GL_DEPTH_TEST);
[3365]107}
[1853]108
[3621]109/**
110   \brief Sets the GL-attributes
111*/
[3617]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
[3621]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*/
[3619]137int GraphicsEngine::setResolution(int width, int height, int bpp)
[3610]138{
[3611]139  this->resolutionX = width;
140  this->resolutionY = height;
141  this->bitsPerPixel = bpp;
142 
[3619]143  printf ("ok\n");
[3621]144  if((this->screen = SDL_SetVideoMode(this->resolutionX, this->resolutionY, this->bitsPerPixel, this->videoFlags)) == NULL)
[3611]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    }
[3610]150
[3543]151}
[3617]152
[3621]153/**
154   \brief Signalhandler, for when the resolution has changed
155   \param resizeInfo SDL information about the size of the new screen size
156*/
[3619]157int GraphicsEngine::resolutionChanged(SDL_ResizeEvent* resizeInfo)
158{
159  this->setResolution(resizeInfo->w, resizeInfo->h, this->bitsPerPixel);
160}
[3617]161
[3622]162/**
163   \brief if Textures should be enabled
164*/
165bool GraphicsEngine::texturesEnabled = true;
[3617]166
167
168
169
170
[3622]171
172
[3617]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.