Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/gui/src/lib/graphics/graphics_engine.cc @ 8475

Last change on this file since 8475 was 8475, checked in by bensch, 19 years ago

yeah a fullscreen button :)

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