Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

trunk: sun

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