Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/new_class_id: almost killed off the old ResourceManager

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"
[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
[7256]29#include "util/preferences.h"
[4770]30#include "substring.h"
[5344]31#include "text.h"
[4770]32
[5819]33#include "globals.h"
[5857]34#include "texture.h"
[5755]35
[9761]36#include "graphics_effect.h"
[6753]37
[6522]38#include "shell_command.h"
[9727]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
[9715]52ObjectListDefinition(GraphicsEngine);
[9685]53
[3245]54/**
[7871]55 * @brief standard constructor
[5262]56 */
[4597]57GraphicsEngine::GraphicsEngine ()
[3365]58{
[9685]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)
[9727]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)
378  const std::list<BaseObject*>* texList = ClassList::getList(CL_TEXTURE);
379  if (texList != NULL)
380  {
381    std::list<BaseObject*>::const_iterator reTex;
382    for (reTex = texList->begin(); reTex != texList->end(); reTex++)
383      dynamic_cast<Texture*>(*reTex)->rebuild();
384  }
385  // REBUILDING MODELS
386  const std::list<BaseObject*>* modelList = ClassList::getList(CL_STATIC_MODEL);
387  if (texList != NULL)
388  {
389    std::list<BaseObject*>::const_iterator reModel;
390    for (reModel = modelList->begin(); reModel != modelList->end(); reModel++)
391      dynamic_cast<StaticModel*>(*reModel)->rebuild();
392  }
[5755]393#endif /* __WIN32__ */
[8316]394  return 1;
[4135]395}
[3610]396
[4458]397/**
[7871]398 * @brief sets Fullscreen mode
[4836]399 * @param fullscreen true if fullscreen, false if windowed
[4458]400*/
[4135]401void GraphicsEngine::setFullscreen(bool fullscreen)
402{
[4768]403  if (fullscreen)
[5789]404    this->fullscreenFlag = SDL_FULLSCREEN;
[4768]405  else
[5789]406    this->fullscreenFlag = 0;
[4135]407  this->setResolution(this->resolutionX, this->resolutionY, this->bitsPerPixel);
[3543]408}
[3617]409
[8518]410void GraphicsEngine::toggleFullscreen()
411{
412  if (this->fullscreenFlag == SDL_FULLSCREEN)
413    this->fullscreenFlag = 0;
414  else
415    this->fullscreenFlag = SDL_FULLSCREEN;
416  this->setResolution(this->resolutionX, this->resolutionY, this->bitsPerPixel);
417}
418
419
[4458]420/**
[7871]421 * @brief sets the background color
[4836]422 * @param red the red part of the background
423 * @param blue the blue part of the background
424 * @param green the green part of the background
425 * @param alpha the alpha part of the background
[5346]426 */
[4374]427void GraphicsEngine::setBackgroundColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
428{
429  glClearColor(red, green, blue, alpha);
430}
431
[3621]432/**
[7871]433 * @brief Signalhandler, for when the resolution has changed
[4836]434 * @param resizeInfo SDL information about the size of the new screen size
[5346]435 */
[8316]436void GraphicsEngine::resolutionChanged(const SDL_ResizeEvent& resizeInfo)
[3619]437{
[4782]438  this->setResolution(resizeInfo.w, resizeInfo.h, this->bitsPerPixel);
[3619]439}
[3617]440
[3622]441/**
[7871]442 * @brief entering 2D Mode
443 * this is a GL-Projection-mode, that is orthogonal, for placing the font in fron of everything else
444 */
[4746]445void GraphicsEngine::enter2DMode()
[3790]446{
[4955]447  //GraphicsEngine::storeMatrices();
[3790]448  SDL_Surface *screen = SDL_GetVideoSurface();
[4597]449
[3790]450  /* Note, there may be other things you need to change,
451     depending on how you have your OpenGL state set up.
452  */
453  glPushAttrib(GL_ENABLE_BIT);
454  glDisable(GL_DEPTH_TEST);
455  glDisable(GL_CULL_FACE);
456  glDisable(GL_LIGHTING);  // will be set back when leaving 2D-mode
[3617]457
[3790]458  glMatrixMode(GL_PROJECTION);
459  glPushMatrix();
460  glLoadIdentity();
461  glOrtho(0.0, (GLdouble)screen->w, (GLdouble)screen->h, 0.0, 0.0, 1.0);
[4597]462
[3790]463  glMatrixMode(GL_MODELVIEW);
464  glPushMatrix();
465  glLoadIdentity();
466}
[3617]467
[3790]468/**
[7871]469 * @brief leaves the 2DMode again also @see Font::enter2DMode()
[5346]470 */
[4746]471void GraphicsEngine::leave2DMode()
[3790]472{
[4597]473
[4834]474  glMatrixMode(GL_MODELVIEW);
[3790]475  glPopMatrix();
[4597]476
[6780]477  glMatrixMode(GL_PROJECTION);
478  glPopMatrix();
479
[3790]480  glPopAttrib();
481}
[3622]482
[7871]483/**
484 * @brief changes to wireframe-mode.
485 */
[6522]486void GraphicsEngine::wireframe()
487{
[6523]488  glPolygonMode(GL_FRONT, GL_LINE);
[6522]489}
490
[3844]491/**
[7871]492 * @brief stores the GL_matrices
[5346]493 */
[4746]494void GraphicsEngine::storeMatrices()
[3844]495{
496  glGetDoublev(GL_PROJECTION_MATRIX, GraphicsEngine::projMat);
497  glGetDoublev(GL_MODELVIEW_MATRIX, GraphicsEngine::modMat);
498  glGetIntegerv(GL_VIEWPORT, GraphicsEngine::viewPort);
499}
[3622]500
[3844]501//! the stored ModelView Matrix.
502GLdouble GraphicsEngine::modMat[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
503//! the stored Projection Matrix
504GLdouble GraphicsEngine::projMat[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
505//! The ViewPort
506GLint GraphicsEngine::viewPort[4] = {0,0,0,0};
[3790]507
508
[3844]509
[3617]510/**
[7871]511 * @brief outputs all the Fullscreen modes.
[5346]512 */
[4746]513void GraphicsEngine::listModes()
[3617]514{
515  /* Get available fullscreen/hardware modes */
516  this->videoModes=SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_HWSURFACE);
[4597]517
[3617]518  /* Check is there are any modes available */
[6979]519  if(this->videoModes == (SDL_Rect **)0)
520  {
[3617]521    PRINTF(1)("No modes available!\n");
522    exit(-1);
523  }
[4597]524
[3617]525  /* Check if our resolution is restricted */
[6979]526  if(this->videoModes == (SDL_Rect **)-1)
527  {
[4135]528    PRINTF(2)("All resolutions available.\n");
[3617]529  }
[6979]530  else
531  {
[3617]532    /* Print valid modes */
533    PRINT(0)("Available Resoulution Modes are\n");
534    for(int i = 0; this->videoModes[i]; ++i)
[4135]535      PRINT(4)(" |  %d x %d\n", this->videoModes[i]->w, this->videoModes[i]->h);
[3617]536  }
[4245]537}
538
[4458]539/**
[7871]540 * @brief checks wether a certain extension is availiable
[5261]541 * @param extension the Extension to check for (ex. GL_ARB_texture_env_dot3)
542 * @return true if it is, false otherwise
543 */
[7221]544bool GraphicsEngine::hwSupportsEXT(const std::string& extension)
[5261]545{
[7319]546  for (unsigned int i = 0; i < this->hwExtensions.size(); i++)
[7221]547    if ( this->hwExtensions.getString(i) == extension)
548      return true;
[5261]549  return false;
550}
551
552/**
[7871]553 * @brief updates everything that is to be updated in the GraphicsEngine
[5084]554 */
555void GraphicsEngine::update(float dt)
556{
[5406]557  Render2D::getInstance()->update(dt);
[5084]558}
559
560
561/**
[7871]562 * @brief ticks the Text
[4836]563 * @param dt the time passed
[5346]564 */
565void GraphicsEngine::tick(float dt)
[4245]566{
[4458]567  if( unlikely(this->bDisplayFPS))
[4849]568  {
569    this->currentFPS = 1.0/dt;
570    if( unlikely(this->currentFPS > this->maxFPS)) this->maxFPS = this->currentFPS;
571    if( unlikely(this->currentFPS < this->minFPS)) this->minFPS = this->currentFPS;
[4597]572
[4536]573#ifndef NO_TEXT
[6979]574    char tmpChar1[20];
575    sprintf(tmpChar1, "Current:  %4.0f", this->currentFPS);
576    this->geTextCFPS->setText(tmpChar1);
577    char tmpChar2[20];
578    sprintf(tmpChar2, "Max:    %4.0f", this->maxFPS);
579    this->geTextMaxFPS->setText(tmpChar2);
580    char tmpChar3[20];
581    sprintf(tmpChar3, "Min:    %4.0f", this->minFPS);
582    this->geTextMinFPS->setText(tmpChar3);
[4536]583#endif /* NO_TEXT */
[4849]584
[6815]585  }
[4849]586
587  Render2D::getInstance()->tick(dt);
[6815]588
589  // tick the graphics effects
[9715]590  for (ObjectList<GraphicsEffect>::const_iterator it = GraphicsEffect::objectList().begin();
[9685]591       it != GraphicsEffect::objectList().end();
592       ++it)
593    (*it)->tick(dt);
[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
[9406]606/**
607 * this draws the graphics engines graphics effecs
608 */
[4849]609void GraphicsEngine::draw() const
610{
[9406]611  if( this->graphicsEffects != NULL)
[6979]612  {
613    //draw the graphics effects
[9406]614    std::list<BaseObject*>::const_iterator it;
[6979]615    for (it = this->graphicsEffects->begin(); it != this->graphicsEffects->end(); it++)
616      dynamic_cast<GraphicsEffect*>(*it)->draw();
617  }
[7428]618  Shader::suspendShader();
[7840]619  Render2D::getInstance()->draw(E2D_LAYER_BOTTOM, E2D_LAYER_ABOVE_ALL);
[7428]620  Shader::restoreShader();
[4849]621}
622
[6142]623
[9406]624void GraphicsEngine::toggleFPSdisplay()
625{
626  this->displayFPS(!this->bDisplayFPS);
627}
628
629
[4458]630/**
[7871]631 * @brief displays the Frames per second
[4836]632 * @param display if the text should be displayed
[4458]633*/
[4245]634void GraphicsEngine::displayFPS(bool display)
635{
[4536]636#ifndef NO_TEXT
[5346]637  if( display )
638  {
[6979]639    if (this->geTextCFPS == NULL)
640    {
641      this->geTextCFPS = new Text("fonts/arial_black.ttf", 15);
642      this->geTextCFPS->setName("curFPS");
643      this->geTextCFPS->setAlignment(TEXT_ALIGN_LEFT);
644      this->geTextCFPS->setAbsCoor2D(5, 0);
645    }
646    if (this->geTextMaxFPS == NULL)
647    {
648      this->geTextMaxFPS = new Text("fonts/arial_black.ttf", 15);
649      this->geTextMaxFPS->setName("MaxFPS");
650      this->geTextMaxFPS->setAlignment(TEXT_ALIGN_LEFT);
651      this->geTextMaxFPS->setAbsCoor2D(5, 20);
652    }
653    if (this->geTextMinFPS == NULL)
654    {
655      this->geTextMinFPS = new Text("fonts/arial_black.ttf", 15);
656      this->geTextMinFPS->setName("MinFPS");
657      this->geTextMinFPS->setAlignment(TEXT_ALIGN_LEFT);
658      this->geTextMinFPS->setAbsCoor2D(5, 40);
659    }
[5346]660  }
[6979]661  else
[5346]662  {
[6979]663    delete this->geTextCFPS;
664    this->geTextCFPS = NULL;
665    delete this->geTextMaxFPS;
666    this->geTextMaxFPS = NULL;
667    delete this->geTextMinFPS;
668    this->geTextMinFPS = NULL;
[5346]669  }
670  this->bDisplayFPS = display;
671#else
672  this->bDisplayFPS = false;
[4536]673#endif /* NO_TEXT */
[3617]674}
[4245]675
[4597]676
[4817]677/**
[7871]678 * @brief processes the events for the GraphicsEngine class
679 * @param the event to handle
[4817]680 */
681void GraphicsEngine::process(const Event &event)
682{
683  switch (event.type)
684  {
[8316]685    case EV_VIDEO_RESIZE:
[9685]686    this->resolutionChanged(event.resize);
687    break;
[4817]688  }
[6753]689}
Note: See TracBrowser for help on using the repository browser.