Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/terrain/src/lib/graphics/graphics_engine.cc @ 9337

Last change on this file since 9337 was 9140, checked in by bensch, 18 years ago

merged back

File size: 17.8 KB
RevLine 
[4597]1/*
[1853]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"
[7193]19#include "util/loading/resource_manager.h"
[6441]20#include "state.h"
[1853]21
[6142]22#include "world_entity.h"
23
[4849]24#include "render_2d.h"
[5347]25#include "text_engine.h"
[4850]26#include "light.h"
[5347]27#include "shader.h"
[3611]28#include "debug.h"
[5347]29
[7256]30#include "util/preferences.h"
[4770]31#include "substring.h"
[5344]32#include "text.h"
[4770]33
[5819]34#include "globals.h"
[5857]35#include "texture.h"
[5755]36
[6753]37#include "effects/graphics_effect.h"
[6772]38#include "effects/fog_effect.h"
[6884]39#include "effects/lense_flare.h"
[6753]40
[6522]41#include "shell_command.h"
42
[6815]43
44#include "parser/tinyxml/tinyxml.h"
[7193]45#include "util/loading/load_param.h"
46#include "util/loading/factory.h"
[6979]47#include "class_list.h"
[6815]48
[5755]49#ifdef __WIN32__
[6162]50 #include "static_model.h"
[5755]51#endif
[1856]52using namespace std;
[1853]53
[6522]54SHELL_COMMAND(wireframe, GraphicsEngine, wireframe);
55
[6976]56
[3245]57/**
[7871]58 * @brief standard constructor
[5262]59 */
[4597]60GraphicsEngine::GraphicsEngine ()
[3365]61{
[4597]62  this->setClassID(CL_GRAPHICS_ENGINE, "GraphicsEngine");
63  this->setName("GraphicsEngine");
[4784]64
65  this->isInit = false;
66
[4245]67  this->bDisplayFPS = false;
[8490]68  this->bAntialiasing = false;
[4245]69  this->minFPS = 9999;
70  this->maxFPS = 0;
[4135]71
[5079]72  this->geTextCFPS = NULL;
73  this->geTextMaxFPS = NULL;
74  this->geTextMinFPS = NULL;
75
[4768]76  this->fullscreenFlag = 0;
[5225]77  this->videoFlags = 0;
78  this->screen = NULL;
[5260]79
[6979]80  // initialize the Modules
[5285]81  TextEngine::getInstance();
[6979]82  this->graphicsEffects = NULL;
83
[3611]84}
[3610]85
[3621]86/**
[7871]87 * @brief The Pointer to this GraphicsEngine
88 */
[3611]89GraphicsEngine* GraphicsEngine::singletonRef = NULL;
[3610]90
[3621]91/**
[7871]92 * @brief destructs the graphicsEngine.
[3611]93*/
[4597]94GraphicsEngine::~GraphicsEngine ()
[3611]95{
96  // delete what has to be deleted here
[7029]97  this->displayFPS( false );
[4849]98
[5286]99  //TextEngine
[5285]100  delete TextEngine::getInstance();
[5347]101  // render 2D
102  delete Render2D::getInstance();
[5079]103
[5225]104  SDL_QuitSubSystem(SDL_INIT_VIDEO);
[6979]105  //   if (this->screen != NULL)
106  //     SDL_FreeSurface(this->screen);
[5240]107
[4849]108  GraphicsEngine::singletonRef = NULL;
[3611]109}
110
[6815]111
[4830]112/**
[7871]113 * @brief loads the GraphicsEngine Specific Parameters.
[6815]114 * @param root: the XML-Element to load the Data From
115 */
116void GraphicsEngine::loadParams(const TiXmlElement* root)
117{
[6979]118  LoadParamXML(root, "GraphicsEffect", this, GraphicsEngine, loadGraphicsEffects)
119  .describe("loads a graphics effect");
[6815]120}
121
122
[6980]123
124
[6815]125/**
[6980]126 * @param root The XML-element to load GraphicsEffects from
127 */
128void GraphicsEngine::loadGraphicsEffects(const TiXmlElement* root)
129{
130  LOAD_PARAM_START_CYCLE(root, element);
131  {
[7035]132    PRINTF(4)("element is: %s\n", element->Value());
[6980]133    Factory::fabricate(element);
134  }
135  LOAD_PARAM_END_CYCLE(element);
136}
137
138
139
140/**
[7871]141 * @brief initializes the GraphicsEngine with default settings.
[4830]142 */
[4784]143int GraphicsEngine::init()
144{
[4830]145  if (this->isInit)
146    return -1;
147  this->initVideo(640, 480, 16);
[8316]148  return 1;
[4784]149}
150
[3611]151/**
[7871]152 * @brief loads the GraphicsEngine's settings from a given ini-file and section
[4830]153 * @returns nothing usefull
154 */
[7256]155int GraphicsEngine::initFromPreferences()
[4830]156{
157  // looking if we are in fullscreen-mode
[7661]158  MultiType fullscreen = Preferences::getInstance()->getString(CONFIG_SECTION_VIDEO, CONFIG_NAME_FULLSCREEN, "0");
[7256]159
[7661]160  if (fullscreen.getBool())
[4830]161    this->fullscreenFlag = SDL_FULLSCREEN;
162
163  // looking if we are in fullscreen-mode
[7661]164  MultiType textures = Preferences::getInstance()->getString(CONFIG_SECTION_VIDEO_ADVANCED, CONFIG_NAME_TEXTURES, "1");
[8316]165  Texture::setTextureEnableState(textures.getBool());
[4830]166
167  // searching for a usefull resolution
[7256]168  SubString resolution(Preferences::getInstance()->getString(CONFIG_SECTION_VIDEO, CONFIG_NAME_RESOLUTION, "640x480").c_str(), 'x'); ///FIXME
[4833]169  //resolution.debug();
[7221]170  MultiType x = resolution.getString(0), y = resolution.getString(1);
[8316]171  return this->initVideo(x.getInt(), y.getInt(), 16);
[4833]172
[6979]173  //   GraphicsEffect* fe = new FogEffect(NULL);
174  //   this->loadGraphicsEffect(fe);
175  //   fe->activate();
176  //   PRINTF(0)("--------------------------------------------------------------\n");
[6884]177
[6967]178  //LenseFlare* ge = new LenseFlare();
179  //this->loadGraphicsEffect(ge);
[6884]180
[6967]181  //ge->addFlare("pictures/lense_flare/sun.png"); //sun
182  //ge->addFlare("pictures/lense_flare/lens2.png"); //first halo
183  //ge->addFlare("pictures/lense_flare/lens1.png"); //small birst
184  //ge->addFlare("pictures/lense_flare/lens3.png"); //second halo
185  //ge->addFlare("pictures/lense_flare/lens4.png");
186  //ge->addFlare("pictures/lense_flare/lens1.png");
187  //ge->addFlare("pictures/lense_flare/lens3.png");
[6884]188
[6966]189  //ge->activate();
[4830]190}
191
192
193
194/**
[7871]195 * @brief initializes the Video for openGL.
[5346]196 *
197 * This has to be done only once when starting orxonox.
198 */
[4784]199int GraphicsEngine::initVideo(unsigned int resX, unsigned int resY, unsigned int bbp)
[3611]200{
[4784]201  if (this->isInit)
202    return -1;
[5024]203  //   initialize SDL_VIDEO
[5225]204  if (SDL_InitSubSystem(SDL_INIT_VIDEO) == -1)
[5024]205  {
206    PRINTF(1)("could not initialize SDL Video\n");
[8316]207    return -1;
[5024]208  }
[3617]209  // initialize SDL_GL-settings
210  this->setGLattribs();
[3610]211
[3617]212  // setting the Video Flags.
[7727]213  this->videoFlags = SDL_OPENGL | SDL_HWPALETTE | SDL_RESIZABLE ;
[3610]214
215  /* query SDL for information about our video hardware */
216  const SDL_VideoInfo* videoInfo = SDL_GetVideoInfo ();
217  if( videoInfo == NULL)
[6979]218  {
219    PRINTF(1)("Failed getting Video Info :%s\n", SDL_GetError());
220    SDL_Quit ();
221  }
[3610]222  if( videoInfo->hw_available)
[3611]223    this->videoFlags |= SDL_HWSURFACE;
[4597]224  else
[3611]225    this->videoFlags |= SDL_SWSURFACE;
[3610]226  /*
[3619]227  if(VideoInfo -> blit_hw)
[3610]228    VideoFlags |= SDL_HWACCEL;
229  */
[6979]230  // setting up the Resolution
[4784]231  this->setResolution(resX, resY, bbp);
[3611]232
[5260]233  // GRABBING ALL GL-extensions
234  this->grabHardwareSettings();
235
[3621]236  // Enable default GL stuff
237  glEnable(GL_DEPTH_TEST);
[9140]238  glEnable(GL_CULL_FACE);
239  glCullFace(GL_FRONT);
[4849]240  Render2D::getInstance();
[4833]241
[4784]242  this->isInit = true;
[8316]243  return 1;
[3365]244}
[1853]245
[4770]246/**
[7871]247 * @brief sets the Window Captions and the Name of the icon.
[4619]248 * @param windowName The name of the Window
249 * @param icon The name of the Icon on the Disc
250 */
[7221]251void GraphicsEngine::setWindowName(const std::string& windowName, const std::string& icon)
[4619]252{
[7221]253  SDL_Surface* iconSurf = SDL_LoadBMP(icon.c_str());
[5240]254  if (iconSurf != NULL)
255  {
[5241]256    Uint32 colorkey = SDL_MapRGB(iconSurf->format, 0, 0, 0);
[5240]257    SDL_SetColorKey(iconSurf, SDL_SRCCOLORKEY, colorkey);
[7221]258    SDL_WM_SetIcon(iconSurf, NULL);
[5240]259    SDL_FreeSurface(iconSurf);
260  }
[5024]261
[7221]262  SDL_WM_SetCaption (windowName.c_str(), icon.c_str());
[4619]263}
264
265
266/**
[7871]267 * @brief Sets the GL-attributes
[5346]268 */
[8316]269void GraphicsEngine::setGLattribs()
[3617]270{
271  // Set video mode
272  // TO DO: parse arguments for settings
273  //SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
274  //SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
275  //SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
276  //SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
277
[4597]278
279  SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
280  SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16);
281  SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, 0);
[3617]282  SDL_GL_SetAttribute( SDL_GL_ACCUM_RED_SIZE, 0);
283  SDL_GL_SetAttribute( SDL_GL_ACCUM_GREEN_SIZE, 0);
284  SDL_GL_SetAttribute( SDL_GL_ACCUM_BLUE_SIZE, 0);
285  SDL_GL_SetAttribute( SDL_GL_ACCUM_ALPHA_SIZE, 0);
[7727]286
[8490]287  SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);      //Use at least 5 bits of Red
288  SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);    //Use at least 5 bits of Green
289  SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);     //Use at least 5 bits of Blue
290  SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);   //Use at least 16 bits for the depth buffer
[7727]291  SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);  //Enable double buffering
[7919]292
[8490]293  // enable antialiasing?
294  if( this->bAntialiasing)
295  {
296    SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES,4);
297    SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS,1);
298  }
299
[9140]300
[3617]301}
302
[5261]303/**
[7871]304 * @brief grabs the Hardware Specifics
305 *
[5261]306 * checks for all the different HW-types
307 */
[5260]308void GraphicsEngine::grabHardwareSettings()
309{
310  const char* renderer = (const char*) glGetString(GL_RENDERER);
311  const char* vendor   = (const char*) glGetString(GL_VENDOR);
312  const char* version  = (const char*) glGetString(GL_VERSION);
313  const char* extensions = (const char*) glGetString(GL_EXTENSIONS);
314
[6979]315  //  printf("%s %s %s\n %s", renderer, vendor, version, extensions);
[5260]316
[7221]317  if (renderer != NULL)
[5260]318  {
[7221]319    this->hwRenderer == renderer;
[5260]320  }
[7221]321  if (vendor != NULL)
[5260]322  {
[7221]323    this->hwVendor == vendor;
[5260]324  }
[7221]325  if (version != NULL)
[5260]326  {
[7221]327    this->hwVersion == version;
[5260]328  }
329
[7221]330  if (extensions != NULL)
331    this->hwExtensions.split(extensions, " \n\t,");
[5260]332
[6634]333  PRINT(4)("Running on : vendor: %s,  renderer: %s,  version:%s\n", vendor, renderer, version);
[5260]334  PRINT(4)("Extensions:\n");
[7319]335  for (unsigned int i = 0; i < this->hwExtensions.size(); i++)
336    PRINT(4)("%d: %s\n", i, this->hwExtensions[i].c_str());
[5263]337
338
339  // inizializing GLEW
340  GLenum err = glewInit();
341  if (GLEW_OK != err)
342  {
343    /* Problem: glewInit failed, something is seriously wrong. */
344    PRINTF(1)("%s\n", glewGetErrorString(err));
345  }
346  PRINTF(4)("Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));
[5260]347}
348
[6162]349
[3621]350/**
[7871]351 * @brief sets the Resolution of the Screen to display the Graphics to.
[4836]352 * @param width The width of the window
353 * @param height The height of the window
354 * @param bpp bits per pixel
[5346]355 */
[3619]356int GraphicsEngine::setResolution(int width, int height, int bpp)
[3610]357{
[3611]358  this->resolutionX = width;
359  this->resolutionY = height;
360  this->bitsPerPixel = bpp;
[6441]361  State::setResolution( width, height);
[4739]362
[5255]363  if (this->screen != NULL)
[5237]364    SDL_FreeSurface(screen);
[4769]365  if((this->screen = SDL_SetVideoMode(this->resolutionX, this->resolutionY, this->bitsPerPixel, this->videoFlags | this->fullscreenFlag)) == NULL)
[6979]366  {
367    PRINTF(1)("Could not SDL_SetVideoMode(%d, %d, %d, %d): %s\n", this->resolutionX, this->resolutionY, this->bitsPerPixel, this->videoFlags, SDL_GetError());
368    //    SDL_Quit();
369    //    return -1;
[8316]370    return -1;
[6979]371  }
372  glViewport(0, 0, width, height);                     // Reset The Current Viewport
[5755]373
[5790]374#ifdef __WIN32__
[6979]375  // REBUILDING TEXTURES (ON WINDOWS CONTEXT SWITCH)
376  const std::list<BaseObject*>* texList = ClassList::getList(CL_TEXTURE);
377  if (texList != NULL)
378  {
379    std::list<BaseObject*>::const_iterator reTex;
380    for (reTex = texList->begin(); reTex != texList->end(); reTex++)
381      dynamic_cast<Texture*>(*reTex)->rebuild();
382  }
383  // REBUILDING MODELS
384  const std::list<BaseObject*>* modelList = ClassList::getList(CL_STATIC_MODEL);
385  if (texList != NULL)
386  {
387    std::list<BaseObject*>::const_iterator reModel;
388    for (reModel = modelList->begin(); reModel != modelList->end(); reModel++)
389      dynamic_cast<StaticModel*>(*reModel)->rebuild();
390  }
[5755]391#endif /* __WIN32__ */
[8316]392  return 1;
[4135]393}
[3610]394
[4458]395/**
[7871]396 * @brief sets Fullscreen mode
[4836]397 * @param fullscreen true if fullscreen, false if windowed
[4458]398*/
[4135]399void GraphicsEngine::setFullscreen(bool fullscreen)
400{
[4768]401  if (fullscreen)
[5789]402    this->fullscreenFlag = SDL_FULLSCREEN;
[4768]403  else
[5789]404    this->fullscreenFlag = 0;
[4135]405  this->setResolution(this->resolutionX, this->resolutionY, this->bitsPerPixel);
[3543]406}
[3617]407
[8518]408void GraphicsEngine::toggleFullscreen()
409{
410  if (this->fullscreenFlag == SDL_FULLSCREEN)
411    this->fullscreenFlag = 0;
412  else
413    this->fullscreenFlag = SDL_FULLSCREEN;
414  this->setResolution(this->resolutionX, this->resolutionY, this->bitsPerPixel);
415}
416
417
[4458]418/**
[7871]419 * @brief sets the background color
[4836]420 * @param red the red part of the background
421 * @param blue the blue part of the background
422 * @param green the green part of the background
423 * @param alpha the alpha part of the background
[5346]424 */
[4374]425void GraphicsEngine::setBackgroundColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
426{
427  glClearColor(red, green, blue, alpha);
428}
429
[3621]430/**
[7871]431 * @brief Signalhandler, for when the resolution has changed
[4836]432 * @param resizeInfo SDL information about the size of the new screen size
[5346]433 */
[8316]434void GraphicsEngine::resolutionChanged(const SDL_ResizeEvent& resizeInfo)
[3619]435{
[4782]436  this->setResolution(resizeInfo.w, resizeInfo.h, this->bitsPerPixel);
[3619]437}
[3617]438
[3622]439/**
[7871]440 * @brief entering 2D Mode
441 * this is a GL-Projection-mode, that is orthogonal, for placing the font in fron of everything else
442 */
[4746]443void GraphicsEngine::enter2DMode()
[3790]444{
[4955]445  //GraphicsEngine::storeMatrices();
[3790]446  SDL_Surface *screen = SDL_GetVideoSurface();
[4597]447
[3790]448  /* Note, there may be other things you need to change,
449     depending on how you have your OpenGL state set up.
450  */
451  glPushAttrib(GL_ENABLE_BIT);
452  glDisable(GL_DEPTH_TEST);
453  glDisable(GL_CULL_FACE);
454  glDisable(GL_LIGHTING);  // will be set back when leaving 2D-mode
[3617]455
[3790]456  glMatrixMode(GL_PROJECTION);
457  glPushMatrix();
458  glLoadIdentity();
459  glOrtho(0.0, (GLdouble)screen->w, (GLdouble)screen->h, 0.0, 0.0, 1.0);
[4597]460
[3790]461  glMatrixMode(GL_MODELVIEW);
462  glPushMatrix();
463  glLoadIdentity();
464}
[3617]465
[3790]466/**
[7871]467 * @brief leaves the 2DMode again also @see Font::enter2DMode()
[5346]468 */
[4746]469void GraphicsEngine::leave2DMode()
[3790]470{
[4597]471
[4834]472  glMatrixMode(GL_MODELVIEW);
[3790]473  glPopMatrix();
[4597]474
[6780]475  glMatrixMode(GL_PROJECTION);
476  glPopMatrix();
477
[3790]478  glPopAttrib();
479}
[3622]480
[7871]481/**
482 * @brief changes to wireframe-mode.
483 */
[6522]484void GraphicsEngine::wireframe()
485{
[6523]486  glPolygonMode(GL_FRONT, GL_LINE);
[6522]487}
488
[3844]489/**
[7871]490 * @brief stores the GL_matrices
[5346]491 */
[4746]492void GraphicsEngine::storeMatrices()
[3844]493{
494  glGetDoublev(GL_PROJECTION_MATRIX, GraphicsEngine::projMat);
495  glGetDoublev(GL_MODELVIEW_MATRIX, GraphicsEngine::modMat);
496  glGetIntegerv(GL_VIEWPORT, GraphicsEngine::viewPort);
497}
[3622]498
[3844]499//! the stored ModelView Matrix.
500GLdouble GraphicsEngine::modMat[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
501//! the stored Projection Matrix
502GLdouble GraphicsEngine::projMat[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
503//! The ViewPort
504GLint GraphicsEngine::viewPort[4] = {0,0,0,0};
[3790]505
506
[3844]507
[3617]508/**
[7871]509 * @brief outputs all the Fullscreen modes.
[5346]510 */
[4746]511void GraphicsEngine::listModes()
[3617]512{
513  /* Get available fullscreen/hardware modes */
514  this->videoModes=SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_HWSURFACE);
[4597]515
[3617]516  /* Check is there are any modes available */
[6979]517  if(this->videoModes == (SDL_Rect **)0)
518  {
[3617]519    PRINTF(1)("No modes available!\n");
520    exit(-1);
521  }
[4597]522
[3617]523  /* Check if our resolution is restricted */
[6979]524  if(this->videoModes == (SDL_Rect **)-1)
525  {
[4135]526    PRINTF(2)("All resolutions available.\n");
[3617]527  }
[6979]528  else
529  {
[3617]530    /* Print valid modes */
531    PRINT(0)("Available Resoulution Modes are\n");
532    for(int i = 0; this->videoModes[i]; ++i)
[4135]533      PRINT(4)(" |  %d x %d\n", this->videoModes[i]->w, this->videoModes[i]->h);
[3617]534  }
[4245]535}
536
[4458]537/**
[7871]538 * @brief checks wether a certain extension is availiable
[5261]539 * @param extension the Extension to check for (ex. GL_ARB_texture_env_dot3)
540 * @return true if it is, false otherwise
541 */
[7221]542bool GraphicsEngine::hwSupportsEXT(const std::string& extension)
[5261]543{
[7319]544  for (unsigned int i = 0; i < this->hwExtensions.size(); i++)
[7221]545    if ( this->hwExtensions.getString(i) == extension)
546      return true;
[5261]547  return false;
548}
549
550/**
[7871]551 * @brief updates everything that is to be updated in the GraphicsEngine
[5084]552 */
553void GraphicsEngine::update(float dt)
554{
[5406]555  Render2D::getInstance()->update(dt);
[5084]556}
557
558
559/**
[7871]560 * @brief ticks the Text
[4836]561 * @param dt the time passed
[5346]562 */
563void GraphicsEngine::tick(float dt)
[4245]564{
[4458]565  if( unlikely(this->bDisplayFPS))
[4849]566  {
567    this->currentFPS = 1.0/dt;
568    if( unlikely(this->currentFPS > this->maxFPS)) this->maxFPS = this->currentFPS;
569    if( unlikely(this->currentFPS < this->minFPS)) this->minFPS = this->currentFPS;
[4597]570
[4536]571#ifndef NO_TEXT
[6979]572    char tmpChar1[20];
573    sprintf(tmpChar1, "Current:  %4.0f", this->currentFPS);
574    this->geTextCFPS->setText(tmpChar1);
575    char tmpChar2[20];
576    sprintf(tmpChar2, "Max:    %4.0f", this->maxFPS);
577    this->geTextMaxFPS->setText(tmpChar2);
578    char tmpChar3[20];
579    sprintf(tmpChar3, "Min:    %4.0f", this->minFPS);
580    this->geTextMinFPS->setText(tmpChar3);
[4536]581#endif /* NO_TEXT */
[4849]582
[6815]583  }
[4849]584
585  Render2D::getInstance()->tick(dt);
[6815]586
587  // tick the graphics effects
[6979]588  if (this->graphicsEffects != NULL || (this->graphicsEffects = ClassList::getList(CL_GRAPHICS_EFFECT)) != NULL)
589  {
590    std::list<BaseObject*>::const_iterator it;
591    for (it = this->graphicsEffects->begin(); it != this->graphicsEffects->end(); it++)
592      dynamic_cast<GraphicsEffect*>(*it)->tick(dt);
593  }
[4245]594}
[4597]595
[7871]596/**
597 * @brief draws all Elements that should be displayed on the Background.
598 */
[7840]599void GraphicsEngine::drawBackgroundElements() const
600{
[7919]601  GraphicsEngine::storeMatrices();
602
[7840]603  Render2D::getInstance()->draw(E2D_LAYER_BELOW_ALL, E2D_LAYER_BELOW_ALL);
604}
[4849]605
606void GraphicsEngine::draw() const
607{
[7221]608  //  LightManager::getInstance()->draw();
[6778]609
[6979]610  if (this->graphicsEffects != NULL)
611  {
612    //draw the graphics effects
613    list<BaseObject*>::const_iterator it;
614    for (it = this->graphicsEffects->begin(); it != this->graphicsEffects->end(); it++)
615      dynamic_cast<GraphicsEffect*>(*it)->draw();
616  }
[7428]617  Shader::suspendShader();
[7840]618  Render2D::getInstance()->draw(E2D_LAYER_BOTTOM, E2D_LAYER_ABOVE_ALL);
[7428]619  Shader::restoreShader();
[4849]620}
621
[6142]622
[4458]623/**
[7871]624 * @brief displays the Frames per second
[4836]625 * @param display if the text should be displayed
[4458]626*/
[4245]627void GraphicsEngine::displayFPS(bool display)
628{
[4536]629#ifndef NO_TEXT
[5346]630  if( display )
631  {
[6979]632    if (this->geTextCFPS == NULL)
633    {
634      this->geTextCFPS = new Text("fonts/arial_black.ttf", 15);
635      this->geTextCFPS->setName("curFPS");
636      this->geTextCFPS->setAlignment(TEXT_ALIGN_LEFT);
637      this->geTextCFPS->setAbsCoor2D(5, 0);
638    }
639    if (this->geTextMaxFPS == NULL)
640    {
641      this->geTextMaxFPS = new Text("fonts/arial_black.ttf", 15);
642      this->geTextMaxFPS->setName("MaxFPS");
643      this->geTextMaxFPS->setAlignment(TEXT_ALIGN_LEFT);
644      this->geTextMaxFPS->setAbsCoor2D(5, 20);
645    }
646    if (this->geTextMinFPS == NULL)
647    {
648      this->geTextMinFPS = new Text("fonts/arial_black.ttf", 15);
649      this->geTextMinFPS->setName("MinFPS");
650      this->geTextMinFPS->setAlignment(TEXT_ALIGN_LEFT);
651      this->geTextMinFPS->setAbsCoor2D(5, 40);
652    }
[5346]653  }
[6979]654  else
[5346]655  {
[6979]656    delete this->geTextCFPS;
657    this->geTextCFPS = NULL;
658    delete this->geTextMaxFPS;
659    this->geTextMaxFPS = NULL;
660    delete this->geTextMinFPS;
661    this->geTextMinFPS = NULL;
[5346]662  }
663  this->bDisplayFPS = display;
664#else
665  this->bDisplayFPS = false;
[4536]666#endif /* NO_TEXT */
[3617]667}
[4245]668
[4597]669
[4817]670/**
[7871]671 * @brief processes the events for the GraphicsEngine class
672 * @param the event to handle
[4817]673 */
674void GraphicsEngine::process(const Event &event)
675{
676  switch (event.type)
677  {
[8316]678    case EV_VIDEO_RESIZE:
679      this->resolutionChanged(event.resize);
680      break;
[4817]681  }
[6753]682}
Note: See TracBrowser for help on using the repository browser.