Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/graphics/graphics_engine.cc @ 10670

Last change on this file since 10670 was 10643, checked in by bknecht, 18 years ago

improvements by landauf on bsp, rotor and wireframe (does build, should work)

File size: 17.9 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
[10618]33#include "orxonox_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
[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)
[9876]378  ObjectList<Texture>::const_iterator retex;
379  for (retex = Texture::objectList().begin(); retex != Texture::objectList().end(); ++retex)
380    (*retex)->rebuild();
381
[6979]382  // REBUILDING MODELS
[9876]383  ObjectList<StaticModel>::const_iterator remod;
384  for (remod = StaticModel::objectList().begin(); remod != StaticModel::objectList().end(); ++remod)
385    (*remod)->rebuild();
386
[5755]387#endif /* __WIN32__ */
[8316]388  return 1;
[4135]389}
[3610]390
[4458]391/**
[7871]392 * @brief sets Fullscreen mode
[4836]393 * @param fullscreen true if fullscreen, false if windowed
[4458]394*/
[4135]395void GraphicsEngine::setFullscreen(bool fullscreen)
396{
[4768]397  if (fullscreen)
[5789]398    this->fullscreenFlag = SDL_FULLSCREEN;
[4768]399  else
[5789]400    this->fullscreenFlag = 0;
[4135]401  this->setResolution(this->resolutionX, this->resolutionY, this->bitsPerPixel);
[3543]402}
[3617]403
[8518]404void GraphicsEngine::toggleFullscreen()
405{
406  if (this->fullscreenFlag == SDL_FULLSCREEN)
407    this->fullscreenFlag = 0;
408  else
409    this->fullscreenFlag = SDL_FULLSCREEN;
410  this->setResolution(this->resolutionX, this->resolutionY, this->bitsPerPixel);
411}
412
413
[4458]414/**
[7871]415 * @brief sets the background color
[4836]416 * @param red the red part of the background
417 * @param blue the blue part of the background
418 * @param green the green part of the background
419 * @param alpha the alpha part of the background
[5346]420 */
[4374]421void GraphicsEngine::setBackgroundColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
422{
423  glClearColor(red, green, blue, alpha);
424}
425
[3621]426/**
[7871]427 * @brief Signalhandler, for when the resolution has changed
[4836]428 * @param resizeInfo SDL information about the size of the new screen size
[5346]429 */
[8316]430void GraphicsEngine::resolutionChanged(const SDL_ResizeEvent& resizeInfo)
[3619]431{
[4782]432  this->setResolution(resizeInfo.w, resizeInfo.h, this->bitsPerPixel);
[3619]433}
[3617]434
[3622]435/**
[7871]436 * @brief entering 2D Mode
437 * this is a GL-Projection-mode, that is orthogonal, for placing the font in fron of everything else
438 */
[4746]439void GraphicsEngine::enter2DMode()
[3790]440{
[4955]441  //GraphicsEngine::storeMatrices();
[3790]442  SDL_Surface *screen = SDL_GetVideoSurface();
[4597]443
[3790]444  /* Note, there may be other things you need to change,
445     depending on how you have your OpenGL state set up.
446  */
447  glPushAttrib(GL_ENABLE_BIT);
448  glDisable(GL_DEPTH_TEST);
449  glDisable(GL_CULL_FACE);
450  glDisable(GL_LIGHTING);  // will be set back when leaving 2D-mode
[3617]451
[3790]452  glMatrixMode(GL_PROJECTION);
453  glPushMatrix();
454  glLoadIdentity();
455  glOrtho(0.0, (GLdouble)screen->w, (GLdouble)screen->h, 0.0, 0.0, 1.0);
[4597]456
[3790]457  glMatrixMode(GL_MODELVIEW);
458  glPushMatrix();
459  glLoadIdentity();
460}
[3617]461
[3790]462/**
[7871]463 * @brief leaves the 2DMode again also @see Font::enter2DMode()
[5346]464 */
[4746]465void GraphicsEngine::leave2DMode()
[3790]466{
[4597]467
[4834]468  glMatrixMode(GL_MODELVIEW);
[3790]469  glPopMatrix();
[4597]470
[6780]471  glMatrixMode(GL_PROJECTION);
472  glPopMatrix();
473
[3790]474  glPopAttrib();
475}
[3622]476
[7871]477/**
478 * @brief changes to wireframe-mode.
479 */
[6522]480void GraphicsEngine::wireframe()
481{
[10643]482  State::showWireframe(!State::showWireframe());
483  /*
484   if (State::showWireframe()){}
485       glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
486   else
487       glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
488  */
[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
[9869]590  for (ObjectList<GraphicsEffect>::const_iterator it = GraphicsEffect::objectList().begin();
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    {
[10320]641      this->geTextCFPS = new Text("fonts/final_frontier.ttf", 15);
[6979]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    {
[10320]648      this->geTextMaxFPS = new Text("fonts/final_frontier.ttf", 15);
[6979]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    {
[10320]655      this->geTextMinFPS = new Text("fonts/final_frontier.ttf", 15);
[6979]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:
[9869]686    this->resolutionChanged(event.resize);
687    break;
[4817]688  }
[6753]689}
Note: See TracBrowser for help on using the repository browser.