Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6886 was 6885, checked in by patrick, 19 years ago

trunk: implemented a working lense-flare

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