Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7028 was 6990, checked in by bensch, 19 years ago

orxonox/trunk: better mouse capture now

File size: 17.5 KB
RevLine 
[4597]1/*
[1853]2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
[1855]10
11   ### File Specific:
[3610]12   main-programmer: Benjamin Grauer
[1855]13   co-programmer: ...
[1853]14*/
15
[3610]16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GRAPHICS
[1853]17
[3610]18#include "graphics_engine.h"
[4094]19#include "resource_manager.h"
[4817]20#include "event_handler.h"
[6441]21#include "state.h"
[1853]22
[6142]23#include "world_entity.h"
24
[4849]25#include "render_2d.h"
[5347]26#include "text_engine.h"
[4850]27#include "light.h"
[5347]28#include "shader.h"
[3611]29#include "debug.h"
[5347]30
[5944]31#include "parser/ini_parser/ini_parser.h"
[4770]32#include "substring.h"
[5344]33#include "text.h"
[4770]34
[5819]35#include "globals.h"
[5857]36#include "texture.h"
[5755]37
[6753]38#include "effects/graphics_effect.h"
[6772]39#include "effects/fog_effect.h"
[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/**
[4836]433 *  entering 2D Mode
[4597]434
[3790]435   this is a GL-Projection-mode, that is orthogonal, for placing the font in fron of everything else
436*/
[4746]437void GraphicsEngine::enter2DMode()
[3790]438{
[4955]439  //GraphicsEngine::storeMatrices();
[3790]440  SDL_Surface *screen = SDL_GetVideoSurface();
[4597]441
[3790]442  /* Note, there may be other things you need to change,
443     depending on how you have your OpenGL state set up.
444  */
445  glPushAttrib(GL_ENABLE_BIT);
446  glDisable(GL_DEPTH_TEST);
447  glDisable(GL_CULL_FACE);
448  glDisable(GL_LIGHTING);  // will be set back when leaving 2D-mode
[3617]449
[3790]450  glMatrixMode(GL_PROJECTION);
451  glPushMatrix();
452  glLoadIdentity();
453  glOrtho(0.0, (GLdouble)screen->w, (GLdouble)screen->h, 0.0, 0.0, 1.0);
[4597]454
[3790]455  glMatrixMode(GL_MODELVIEW);
456  glPushMatrix();
457  glLoadIdentity();
458}
[3617]459
[3790]460/**
[5346]461 *  leaves the 2DMode again also @see Font::enter2DMode()
462 */
[4746]463void GraphicsEngine::leave2DMode()
[3790]464{
[4597]465
[4834]466  glMatrixMode(GL_MODELVIEW);
[3790]467  glPopMatrix();
[4597]468
[6780]469  glMatrixMode(GL_PROJECTION);
470  glPopMatrix();
471
[3790]472  glPopAttrib();
473}
[3622]474
[6522]475void GraphicsEngine::wireframe()
476{
[6523]477  glPolygonMode(GL_FRONT, GL_LINE);
[6522]478}
479
[3844]480/**
[4836]481 *  stores the GL_matrices
[5346]482 */
[4746]483void GraphicsEngine::storeMatrices()
[3844]484{
485  glGetDoublev(GL_PROJECTION_MATRIX, GraphicsEngine::projMat);
486  glGetDoublev(GL_MODELVIEW_MATRIX, GraphicsEngine::modMat);
487  glGetIntegerv(GL_VIEWPORT, GraphicsEngine::viewPort);
488}
[3622]489
[3844]490//! the stored ModelView Matrix.
491GLdouble GraphicsEngine::modMat[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
492//! the stored Projection Matrix
493GLdouble GraphicsEngine::projMat[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
494//! The ViewPort
495GLint GraphicsEngine::viewPort[4] = {0,0,0,0};
[3790]496
497
[3844]498
[3617]499/**
[4836]500 *  outputs all the Fullscreen modes.
[5346]501 */
[4746]502void GraphicsEngine::listModes()
[3617]503{
504  /* Get available fullscreen/hardware modes */
505  this->videoModes=SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_HWSURFACE);
[4597]506
[3617]507  /* Check is there are any modes available */
[6979]508  if(this->videoModes == (SDL_Rect **)0)
509  {
[3617]510    PRINTF(1)("No modes available!\n");
511    exit(-1);
512  }
[4597]513
[3617]514  /* Check if our resolution is restricted */
[6979]515  if(this->videoModes == (SDL_Rect **)-1)
516  {
[4135]517    PRINTF(2)("All resolutions available.\n");
[3617]518  }
[6979]519  else
520  {
[3617]521    /* Print valid modes */
522    PRINT(0)("Available Resoulution Modes are\n");
523    for(int i = 0; this->videoModes[i]; ++i)
[4135]524      PRINT(4)(" |  %d x %d\n", this->videoModes[i]->w, this->videoModes[i]->h);
[3617]525  }
[4245]526}
527
[4458]528/**
[5261]529 * checks wether a certain extension is availiable
530 * @param extension the Extension to check for (ex. GL_ARB_texture_env_dot3)
531 * @return true if it is, false otherwise
532 */
533bool GraphicsEngine::hwSupportsEXT(const char* extension)
534{
535  if (this->hwExtensions != NULL)
536    for (unsigned int i = 0; i < this->hwExtensions->getCount(); i++)
537      if (!strcmp(extension, this->hwExtensions->getString(i)))
538        return true;
539  return false;
540}
541
542/**
[5084]543 * updates everything that is to be updated in the GraphicsEngine
544 */
545void GraphicsEngine::update(float dt)
546{
[5406]547  Render2D::getInstance()->update(dt);
[5084]548}
549
550
551/**
[4836]552 *  ticks the Text
553 * @param dt the time passed
[5346]554 */
555void GraphicsEngine::tick(float dt)
[4245]556{
[4458]557  if( unlikely(this->bDisplayFPS))
[4849]558  {
559    this->currentFPS = 1.0/dt;
560    if( unlikely(this->currentFPS > this->maxFPS)) this->maxFPS = this->currentFPS;
561    if( unlikely(this->currentFPS < this->minFPS)) this->minFPS = this->currentFPS;
[4597]562
[4536]563#ifndef NO_TEXT
[6979]564    char tmpChar1[20];
565    sprintf(tmpChar1, "Current:  %4.0f", this->currentFPS);
566    this->geTextCFPS->setText(tmpChar1);
567    char tmpChar2[20];
568    sprintf(tmpChar2, "Max:    %4.0f", this->maxFPS);
569    this->geTextMaxFPS->setText(tmpChar2);
570    char tmpChar3[20];
571    sprintf(tmpChar3, "Min:    %4.0f", this->minFPS);
572    this->geTextMinFPS->setText(tmpChar3);
[4536]573#endif /* NO_TEXT */
[4849]574
[6815]575  }
[4849]576
577  Render2D::getInstance()->tick(dt);
[6815]578
579  // tick the graphics effects
[6979]580  if (this->graphicsEffects != NULL || (this->graphicsEffects = ClassList::getList(CL_GRAPHICS_EFFECT)) != NULL)
581  {
582    std::list<BaseObject*>::const_iterator it;
583    for (it = this->graphicsEffects->begin(); it != this->graphicsEffects->end(); it++)
584      dynamic_cast<GraphicsEffect*>(*it)->tick(dt);
585  }
[4245]586}
[4597]587
[4849]588
589void GraphicsEngine::draw() const
590{
[6778]591
[5417]592  LightManager::getInstance()->draw();
[6778]593
[6780]594  GraphicsEngine::storeMatrices();
[5318]595  Shader::suspendShader();
[5417]596
[5397]597  Render2D::getInstance()->draw(E2D_LAYER_ALL);
[5318]598  Shader::restoreShader();
[6815]599
[6979]600  if (this->graphicsEffects != NULL)
601  {
602    //draw the graphics effects
603    list<BaseObject*>::const_iterator it;
604    for (it = this->graphicsEffects->begin(); it != this->graphicsEffects->end(); it++)
605      dynamic_cast<GraphicsEffect*>(*it)->draw();
606  }
[4849]607}
608
[6142]609void GraphicsEngine::draw(const std::list<WorldEntity*>& drawList ) const
610{
611  std::list<WorldEntity*>::const_iterator entity;
612  for (entity = drawList.begin(); entity != drawList.end(); entity++)
[6222]613    if ((*entity)->isVisible())
614      (*entity)->draw();
[6142]615}
616
617
[4458]618/**
[5346]619 * displays the Frames per second
[4836]620 * @param display if the text should be displayed
[4458]621*/
[4245]622void GraphicsEngine::displayFPS(bool display)
623{
[4536]624#ifndef NO_TEXT
[5346]625  if( display )
626  {
[6979]627    if (this->geTextCFPS == NULL)
628    {
629      this->geTextCFPS = new Text("fonts/arial_black.ttf", 15);
630      this->geTextCFPS->setName("curFPS");
631      this->geTextCFPS->setAlignment(TEXT_ALIGN_LEFT);
632      this->geTextCFPS->setAbsCoor2D(5, 0);
633    }
634    if (this->geTextMaxFPS == NULL)
635    {
636      this->geTextMaxFPS = new Text("fonts/arial_black.ttf", 15);
637      this->geTextMaxFPS->setName("MaxFPS");
638      this->geTextMaxFPS->setAlignment(TEXT_ALIGN_LEFT);
639      this->geTextMaxFPS->setAbsCoor2D(5, 20);
640    }
641    if (this->geTextMinFPS == NULL)
642    {
643      this->geTextMinFPS = new Text("fonts/arial_black.ttf", 15);
644      this->geTextMinFPS->setName("MinFPS");
645      this->geTextMinFPS->setAlignment(TEXT_ALIGN_LEFT);
646      this->geTextMinFPS->setAbsCoor2D(5, 40);
647    }
[5346]648  }
[6979]649  else
[5346]650  {
[6979]651    delete this->geTextCFPS;
652    this->geTextCFPS = NULL;
653    delete this->geTextMaxFPS;
654    this->geTextMaxFPS = NULL;
655    delete this->geTextMinFPS;
656    this->geTextMinFPS = NULL;
[5346]657  }
658  this->bDisplayFPS = display;
659#else
660  this->bDisplayFPS = false;
[4536]661#endif /* NO_TEXT */
[3617]662}
[4245]663
[4597]664
[4817]665/**
[5346]666  processes the events for the GraphicsEngine class
[4836]667* @param the event to handle
[4817]668 */
669void GraphicsEngine::process(const Event &event)
670{
671  switch (event.type)
672  {
[6979]673      case EV_VIDEO_RESIZE:
[4817]674      this->resolutionChanged(event.resize);
675      break;
676  }
[6753]677}
Note: See TracBrowser for help on using the repository browser.