Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/new_class_id: new Executor construct, that is much more typesafe, faster, and easier to extend…

Also changed the LoadParam process, and adapted ScriptEngine calls

Then at the end, some missing headers appeared, and appended them to all the cc-files again.

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