Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: merged branches/network back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/network . -r6774:HEAD

no conflicts…
thats what i call orthogonal work

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