Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8699 was 8697, checked in by patrick, 19 years ago

merged the terrain with the new trunk (MARK TERRAIN)

File size: 17.9 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);
[8697]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
[7919]300  glEnable(GL_CULL_FACE);
301  glCullFace(GL_FRONT);
[3617]302}
303
[5261]304/**
[7871]305 * @brief grabs the Hardware Specifics
306 *
[5261]307 * checks for all the different HW-types
308 */
[5260]309void GraphicsEngine::grabHardwareSettings()
310{
311  const char* renderer = (const char*) glGetString(GL_RENDERER);
312  const char* vendor   = (const char*) glGetString(GL_VENDOR);
313  const char* version  = (const char*) glGetString(GL_VERSION);
314  const char* extensions = (const char*) glGetString(GL_EXTENSIONS);
315
[6979]316  //  printf("%s %s %s\n %s", renderer, vendor, version, extensions);
[5260]317
[7221]318  if (renderer != NULL)
[5260]319  {
[7221]320    this->hwRenderer == renderer;
[5260]321  }
[7221]322  if (vendor != NULL)
[5260]323  {
[7221]324    this->hwVendor == vendor;
[5260]325  }
[7221]326  if (version != NULL)
[5260]327  {
[7221]328    this->hwVersion == version;
[5260]329  }
330
[7221]331  if (extensions != NULL)
332    this->hwExtensions.split(extensions, " \n\t,");
[5260]333
[6634]334  PRINT(4)("Running on : vendor: %s,  renderer: %s,  version:%s\n", vendor, renderer, version);
[5260]335  PRINT(4)("Extensions:\n");
[7319]336  for (unsigned int i = 0; i < this->hwExtensions.size(); i++)
337    PRINT(4)("%d: %s\n", i, this->hwExtensions[i].c_str());
[5263]338
339
340  // inizializing GLEW
341  GLenum err = glewInit();
342  if (GLEW_OK != err)
343  {
344    /* Problem: glewInit failed, something is seriously wrong. */
345    PRINTF(1)("%s\n", glewGetErrorString(err));
346  }
347  PRINTF(4)("Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));
[5260]348}
349
[6162]350
[3621]351/**
[7871]352 * @brief sets the Resolution of the Screen to display the Graphics to.
[4836]353 * @param width The width of the window
354 * @param height The height of the window
355 * @param bpp bits per pixel
[5346]356 */
[3619]357int GraphicsEngine::setResolution(int width, int height, int bpp)
[3610]358{
[3611]359  this->resolutionX = width;
360  this->resolutionY = height;
361  this->bitsPerPixel = bpp;
[6441]362  State::setResolution( width, height);
[4739]363
[5255]364  if (this->screen != NULL)
[5237]365    SDL_FreeSurface(screen);
[4769]366  if((this->screen = SDL_SetVideoMode(this->resolutionX, this->resolutionY, this->bitsPerPixel, this->videoFlags | this->fullscreenFlag)) == NULL)
[6979]367  {
368    PRINTF(1)("Could not SDL_SetVideoMode(%d, %d, %d, %d): %s\n", this->resolutionX, this->resolutionY, this->bitsPerPixel, this->videoFlags, SDL_GetError());
369    //    SDL_Quit();
370    //    return -1;
[8316]371    return -1;
[6979]372  }
373  glViewport(0, 0, width, height);                     // Reset The Current Viewport
[5755]374
[5790]375#ifdef __WIN32__
[6979]376  // REBUILDING TEXTURES (ON WINDOWS CONTEXT SWITCH)
377  const std::list<BaseObject*>* texList = ClassList::getList(CL_TEXTURE);
378  if (texList != NULL)
379  {
380    std::list<BaseObject*>::const_iterator reTex;
381    for (reTex = texList->begin(); reTex != texList->end(); reTex++)
382      dynamic_cast<Texture*>(*reTex)->rebuild();
383  }
384  // REBUILDING MODELS
385  const std::list<BaseObject*>* modelList = ClassList::getList(CL_STATIC_MODEL);
386  if (texList != NULL)
387  {
388    std::list<BaseObject*>::const_iterator reModel;
389    for (reModel = modelList->begin(); reModel != modelList->end(); reModel++)
390      dynamic_cast<StaticModel*>(*reModel)->rebuild();
391  }
[5755]392#endif /* __WIN32__ */
[8316]393  return 1;
[4135]394}
[3610]395
[4458]396/**
[7871]397 * @brief sets Fullscreen mode
[4836]398 * @param fullscreen true if fullscreen, false if windowed
[4458]399*/
[4135]400void GraphicsEngine::setFullscreen(bool fullscreen)
401{
[4768]402  if (fullscreen)
[5789]403    this->fullscreenFlag = SDL_FULLSCREEN;
[4768]404  else
[5789]405    this->fullscreenFlag = 0;
[4135]406  this->setResolution(this->resolutionX, this->resolutionY, this->bitsPerPixel);
[3543]407}
[3617]408
[8518]409void GraphicsEngine::toggleFullscreen()
410{
411  if (this->fullscreenFlag == SDL_FULLSCREEN)
412    this->fullscreenFlag = 0;
413  else
414    this->fullscreenFlag = SDL_FULLSCREEN;
415  this->setResolution(this->resolutionX, this->resolutionY, this->bitsPerPixel);
416}
417
418
[4458]419/**
[7871]420 * @brief sets the background color
[4836]421 * @param red the red part of the background
422 * @param blue the blue part of the background
423 * @param green the green part of the background
424 * @param alpha the alpha part of the background
[5346]425 */
[4374]426void GraphicsEngine::setBackgroundColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
427{
428  glClearColor(red, green, blue, alpha);
429}
430
[3621]431/**
[7871]432 * @brief Signalhandler, for when the resolution has changed
[4836]433 * @param resizeInfo SDL information about the size of the new screen size
[5346]434 */
[8316]435void GraphicsEngine::resolutionChanged(const SDL_ResizeEvent& resizeInfo)
[3619]436{
[4782]437  this->setResolution(resizeInfo.w, resizeInfo.h, this->bitsPerPixel);
[3619]438}
[3617]439
[3622]440/**
[7871]441 * @brief entering 2D Mode
442 * this is a GL-Projection-mode, that is orthogonal, for placing the font in fron of everything else
443 */
[4746]444void GraphicsEngine::enter2DMode()
[3790]445{
[4955]446  //GraphicsEngine::storeMatrices();
[3790]447  SDL_Surface *screen = SDL_GetVideoSurface();
[4597]448
[3790]449  /* Note, there may be other things you need to change,
450     depending on how you have your OpenGL state set up.
451  */
452  glPushAttrib(GL_ENABLE_BIT);
453  glDisable(GL_DEPTH_TEST);
454  glDisable(GL_CULL_FACE);
455  glDisable(GL_LIGHTING);  // will be set back when leaving 2D-mode
[3617]456
[3790]457  glMatrixMode(GL_PROJECTION);
458  glPushMatrix();
459  glLoadIdentity();
460  glOrtho(0.0, (GLdouble)screen->w, (GLdouble)screen->h, 0.0, 0.0, 1.0);
[4597]461
[3790]462  glMatrixMode(GL_MODELVIEW);
463  glPushMatrix();
464  glLoadIdentity();
465}
[3617]466
[3790]467/**
[7871]468 * @brief leaves the 2DMode again also @see Font::enter2DMode()
[5346]469 */
[4746]470void GraphicsEngine::leave2DMode()
[3790]471{
[4597]472
[4834]473  glMatrixMode(GL_MODELVIEW);
[3790]474  glPopMatrix();
[4597]475
[6780]476  glMatrixMode(GL_PROJECTION);
477  glPopMatrix();
478
[3790]479  glPopAttrib();
480}
[3622]481
[7871]482/**
483 * @brief changes to wireframe-mode.
484 */
[6522]485void GraphicsEngine::wireframe()
486{
[6523]487  glPolygonMode(GL_FRONT, GL_LINE);
[6522]488}
489
[3844]490/**
[7871]491 * @brief stores the GL_matrices
[5346]492 */
[4746]493void GraphicsEngine::storeMatrices()
[3844]494{
495  glGetDoublev(GL_PROJECTION_MATRIX, GraphicsEngine::projMat);
496  glGetDoublev(GL_MODELVIEW_MATRIX, GraphicsEngine::modMat);
497  glGetIntegerv(GL_VIEWPORT, GraphicsEngine::viewPort);
498}
[3622]499
[3844]500//! the stored ModelView Matrix.
501GLdouble GraphicsEngine::modMat[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
502//! the stored Projection Matrix
503GLdouble GraphicsEngine::projMat[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
504//! The ViewPort
505GLint GraphicsEngine::viewPort[4] = {0,0,0,0};
[3790]506
507
[3844]508
[3617]509/**
[7871]510 * @brief outputs all the Fullscreen modes.
[5346]511 */
[4746]512void GraphicsEngine::listModes()
[3617]513{
514  /* Get available fullscreen/hardware modes */
515  this->videoModes=SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_HWSURFACE);
[4597]516
[3617]517  /* Check is there are any modes available */
[6979]518  if(this->videoModes == (SDL_Rect **)0)
519  {
[3617]520    PRINTF(1)("No modes available!\n");
521    exit(-1);
522  }
[4597]523
[3617]524  /* Check if our resolution is restricted */
[6979]525  if(this->videoModes == (SDL_Rect **)-1)
526  {
[4135]527    PRINTF(2)("All resolutions available.\n");
[3617]528  }
[6979]529  else
530  {
[3617]531    /* Print valid modes */
532    PRINT(0)("Available Resoulution Modes are\n");
533    for(int i = 0; this->videoModes[i]; ++i)
[4135]534      PRINT(4)(" |  %d x %d\n", this->videoModes[i]->w, this->videoModes[i]->h);
[3617]535  }
[4245]536}
537
[4458]538/**
[7871]539 * @brief checks wether a certain extension is availiable
[5261]540 * @param extension the Extension to check for (ex. GL_ARB_texture_env_dot3)
541 * @return true if it is, false otherwise
542 */
[7221]543bool GraphicsEngine::hwSupportsEXT(const std::string& extension)
[5261]544{
[7319]545  for (unsigned int i = 0; i < this->hwExtensions.size(); i++)
[7221]546    if ( this->hwExtensions.getString(i) == extension)
547      return true;
[5261]548  return false;
549}
550
551/**
[7871]552 * @brief updates everything that is to be updated in the GraphicsEngine
[5084]553 */
554void GraphicsEngine::update(float dt)
555{
[5406]556  Render2D::getInstance()->update(dt);
[5084]557}
558
559
560/**
[7871]561 * @brief ticks the Text
[4836]562 * @param dt the time passed
[5346]563 */
564void GraphicsEngine::tick(float dt)
[4245]565{
[4458]566  if( unlikely(this->bDisplayFPS))
[4849]567  {
568    this->currentFPS = 1.0/dt;
569    if( unlikely(this->currentFPS > this->maxFPS)) this->maxFPS = this->currentFPS;
570    if( unlikely(this->currentFPS < this->minFPS)) this->minFPS = this->currentFPS;
[4597]571
[4536]572#ifndef NO_TEXT
[6979]573    char tmpChar1[20];
574    sprintf(tmpChar1, "Current:  %4.0f", this->currentFPS);
575    this->geTextCFPS->setText(tmpChar1);
576    char tmpChar2[20];
577    sprintf(tmpChar2, "Max:    %4.0f", this->maxFPS);
578    this->geTextMaxFPS->setText(tmpChar2);
579    char tmpChar3[20];
580    sprintf(tmpChar3, "Min:    %4.0f", this->minFPS);
581    this->geTextMinFPS->setText(tmpChar3);
[4536]582#endif /* NO_TEXT */
[4849]583
[6815]584  }
[4849]585
586  Render2D::getInstance()->tick(dt);
[6815]587
588  // tick the graphics effects
[6979]589  if (this->graphicsEffects != NULL || (this->graphicsEffects = ClassList::getList(CL_GRAPHICS_EFFECT)) != NULL)
590  {
591    std::list<BaseObject*>::const_iterator it;
592    for (it = this->graphicsEffects->begin(); it != this->graphicsEffects->end(); it++)
593      dynamic_cast<GraphicsEffect*>(*it)->tick(dt);
594  }
[4245]595}
[4597]596
[7871]597/**
598 * @brief draws all Elements that should be displayed on the Background.
599 */
[7840]600void GraphicsEngine::drawBackgroundElements() const
601{
[7919]602  GraphicsEngine::storeMatrices();
603
[7840]604  Render2D::getInstance()->draw(E2D_LAYER_BELOW_ALL, E2D_LAYER_BELOW_ALL);
605}
[4849]606
607void GraphicsEngine::draw() const
608{
[7221]609  //  LightManager::getInstance()->draw();
[6778]610
[6979]611  if (this->graphicsEffects != NULL)
612  {
613    //draw the graphics effects
614    list<BaseObject*>::const_iterator it;
615    for (it = this->graphicsEffects->begin(); it != this->graphicsEffects->end(); it++)
616      dynamic_cast<GraphicsEffect*>(*it)->draw();
617  }
[7428]618  GraphicsEngine::storeMatrices();
619  Shader::suspendShader();
[7840]620  Render2D::getInstance()->draw(E2D_LAYER_BOTTOM, E2D_LAYER_ABOVE_ALL);
[7428]621  Shader::restoreShader();
[4849]622}
623
[6142]624
[4458]625/**
[7871]626 * @brief displays the Frames per second
[4836]627 * @param display if the text should be displayed
[4458]628*/
[4245]629void GraphicsEngine::displayFPS(bool display)
630{
[4536]631#ifndef NO_TEXT
[5346]632  if( display )
633  {
[6979]634    if (this->geTextCFPS == NULL)
635    {
636      this->geTextCFPS = new Text("fonts/arial_black.ttf", 15);
637      this->geTextCFPS->setName("curFPS");
638      this->geTextCFPS->setAlignment(TEXT_ALIGN_LEFT);
639      this->geTextCFPS->setAbsCoor2D(5, 0);
640    }
641    if (this->geTextMaxFPS == NULL)
642    {
643      this->geTextMaxFPS = new Text("fonts/arial_black.ttf", 15);
644      this->geTextMaxFPS->setName("MaxFPS");
645      this->geTextMaxFPS->setAlignment(TEXT_ALIGN_LEFT);
646      this->geTextMaxFPS->setAbsCoor2D(5, 20);
647    }
648    if (this->geTextMinFPS == NULL)
649    {
650      this->geTextMinFPS = new Text("fonts/arial_black.ttf", 15);
651      this->geTextMinFPS->setName("MinFPS");
652      this->geTextMinFPS->setAlignment(TEXT_ALIGN_LEFT);
653      this->geTextMinFPS->setAbsCoor2D(5, 40);
654    }
[5346]655  }
[6979]656  else
[5346]657  {
[6979]658    delete this->geTextCFPS;
659    this->geTextCFPS = NULL;
660    delete this->geTextMaxFPS;
661    this->geTextMaxFPS = NULL;
662    delete this->geTextMinFPS;
663    this->geTextMinFPS = NULL;
[5346]664  }
665  this->bDisplayFPS = display;
666#else
667  this->bDisplayFPS = false;
[4536]668#endif /* NO_TEXT */
[3617]669}
[4245]670
[4597]671
[4817]672/**
[7871]673 * @brief processes the events for the GraphicsEngine class
674 * @param the event to handle
[4817]675 */
676void GraphicsEngine::process(const Event &event)
677{
678  switch (event.type)
679  {
[8316]680    case EV_VIDEO_RESIZE:
681      this->resolutionChanged(event.resize);
682      break;
[4817]683  }
[6753]684}
Note: See TracBrowser for help on using the repository browser.