Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10621 was 10618, checked in by bknecht, 18 years ago

merged cleanup into trunk (only improvements)

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