Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

trunk: lenseflares loadable

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