Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6978 was 6978, checked in by bensch, 18 years ago

orxonox/trunk: loads the stuff

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