Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/volumetric_fog/src/lib/graphics/graphics_engine.cc @ 9935

Last change on this file since 9935 was 9935, checked in by hdavid, 18 years ago

branches/volumetric_gof: empty base files

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