/*! * @file graphics_engine.h * defines a Interface between orxonox and graphical input handles graphical SDL-initialisation, textures, resolutions, and so on */ #ifndef _GRAPHICS_ENGINE_H #define _GRAPHICS_ENGINE_H #include "event_listener.h" #include "sdlincl.h" #include "glincl.h" #include #include "substring.h" // Forward Declaration class Text; class WorldEntity; class GraphicsEffect; class TiXmlElement; //! class to handle graphics /** handles graphical SDL-initialisation, textures, resolutions, and so on */ class GraphicsEngine : public EventListener { ObjectListDeclaration(GraphicsEngine); public: virtual ~GraphicsEngine(); /** @returns a Pointer to the only object of this Class */ inline static GraphicsEngine* getInstance() { if (!GraphicsEngine::singletonRef) GraphicsEngine::singletonRef = new GraphicsEngine(); return GraphicsEngine::singletonRef; }; virtual void loadParams(const TiXmlElement* root); int init(); int initFromPreferences(); void setWindowName(const std::string& windowName, const std::string& icon); int setResolution(int width, int height, int bpp); void setFullscreen(bool fullscreen = false); void toggleFullscreen(); static void setBackgroundColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha = 1.0); inline bool isDedicated() { return this->bDedicated; } inline void setAntialiasing(bool flag) { this->bAntialiasing = flag; } inline bool getAntialiasing() { return this->bAntialiasing; } /** @returns the x resolution */ inline int getResolutionX() const { return this->resolutionX; }; /** @returns the y resolution */ inline int getResolutionY() const { return this->resolutionY; }; /** @returns the Bits Per Pixel */ inline int getbbp() const { return this->bitsPerPixel; }; void resolutionChanged(const SDL_ResizeEvent& resizeInfo); static void enter2DMode(); static void leave2DMode(); void wireframe(); static void storeMatrices(); static GLdouble modMat[16]; static GLdouble projMat[16]; static GLint viewPort[4]; void update(float dt); void tick(float dt); void drawBackgroundElements() const; void draw() const; void toggleFPSdisplay(); void displayFPS(bool display); void listModes(); bool hwSupportsEXT(const std::string& extension); /** @brief swaps the GL_BUFFERS */ inline static void swapBuffers() { SDL_GL_SwapBuffers(); }; void process(const Event &event); void loadGraphicsEffects(const TiXmlElement* root); private: GraphicsEngine(); int initVideo(unsigned int resX, unsigned int resY, unsigned int bbp); void setGLattribs(); void grabHardwareSettings(); public: private: static GraphicsEngine* singletonRef; //!< Pointer to the only instance of this Class bool isInit; //!< if the GraphicsEngine is initialized. // state. SDL_Surface* screen; //!< the screen we draw to int resolutionX; //!< the X-resoultion of the screen int resolutionY; //!< the Y-resolution of the screen int bitsPerPixel; //!< the bits per pixels of the screen Uint32 fullscreenFlag; //!< if we are in fullscreen mode Uint32 videoFlags; //!< flags for video SDL_Rect** videoModes; //!< list of resolutions bool fogEnabled; //!< If Fog should be enabled. bool shadowsEnabled; //!< If Shadows should be enabled. bool particlesEnabled; //!< If particles should be enabled. bool bAntialiasing; //!< true if antialiasing enabled bool bDedicated; //!< true if this server is a dedicated server and should not render the scene int particlesValue; //!< How many particles int textureQuality; //!< the quality of Textures int filteringMethod; //!< The filtering Method of textures. int modelQuality; //!< The quality of the Models loaded. int antialiasingDepth; //!< the Depth of the AntiAlias-Filter. // HARDWARE-Settings: std::string hwRenderer; //!< HW-renderer-string std::string hwVendor; //!< HW-vendor-string std::string hwVersion; //!< HW-version-string SubString hwExtensions; //!< All suported Extensions. // FPS-related bool bDisplayFPS; //!< is true if the fps should be displayed float currentFPS; //!< the current frame rate: frames per seconds float maxFPS; //!< maximal frame rate we ever got since start of the game float minFPS; //!< minimal frame rate we ever got since start. const std::list* graphicsEffects; //!< list of graphics effects #ifndef NO_TEXT Text* geTextCFPS; //!< Text for the current FPS Text* geTextMaxFPS; //!< Text for the max FPS Text* geTextMinFPS; //!< Text for the min FPS #endif /* NO_TEXT */ }; #endif /* _GRAPHICS_ENGINE_H */