Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/new_class_id/src/lib/graphics/graphics_engine.cc @ 9760

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

moved around the weather effecs

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