1 | /*! |
---|
2 | * @file graphics_engine.h |
---|
3 | |
---|
4 | * defines a Interface between orxonox and graphical input |
---|
5 | |
---|
6 | handles graphical SDL-initialisation, textures, resolutions, and so on |
---|
7 | */ |
---|
8 | |
---|
9 | #ifndef _GRAPHICS_ENGINE_H |
---|
10 | #define _GRAPHICS_ENGINE_H |
---|
11 | |
---|
12 | #include "event_listener.h" |
---|
13 | |
---|
14 | #include "sdlincl.h" |
---|
15 | #include "glincl.h" |
---|
16 | #include <list> |
---|
17 | |
---|
18 | #include "substring.h" |
---|
19 | |
---|
20 | // Forward Declaration |
---|
21 | class Text; |
---|
22 | class WorldEntity; |
---|
23 | class GraphicsEffect; |
---|
24 | class TiXmlElement; |
---|
25 | |
---|
26 | //! class to handle graphics |
---|
27 | /** |
---|
28 | handles graphical SDL-initialisation, textures, resolutions, and so on |
---|
29 | */ |
---|
30 | class GraphicsEngine : public EventListener |
---|
31 | { |
---|
32 | public: |
---|
33 | virtual ~GraphicsEngine(); |
---|
34 | /** @returns a Pointer to the only object of this Class */ |
---|
35 | inline static GraphicsEngine* getInstance() { if (!GraphicsEngine::singletonRef) GraphicsEngine::singletonRef = new GraphicsEngine(); return GraphicsEngine::singletonRef; }; |
---|
36 | |
---|
37 | virtual void loadParams(const TiXmlElement* root); |
---|
38 | |
---|
39 | int init(); |
---|
40 | int initFromPreferences(); |
---|
41 | |
---|
42 | void setWindowName(const std::string& windowName, const std::string& icon); |
---|
43 | |
---|
44 | int setResolution(int width, int height, int bpp); |
---|
45 | void setFullscreen(bool fullscreen = false); |
---|
46 | void toggleFullscreen(); |
---|
47 | static void setBackgroundColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha = 1.0); |
---|
48 | |
---|
49 | inline void setAntialiasing(bool flag) { this->bAntialiasing = flag; } |
---|
50 | inline bool getAntialiasing() { return this->bAntialiasing; } |
---|
51 | |
---|
52 | /** @returns the x resolution */ |
---|
53 | inline int getResolutionX() const { return this->resolutionX; }; |
---|
54 | /** @returns the y resolution */ |
---|
55 | inline int getResolutionY() const { return this->resolutionY; }; |
---|
56 | /** @returns the Bits Per Pixel */ |
---|
57 | inline int getbbp() const { return this->bitsPerPixel; }; |
---|
58 | |
---|
59 | void resolutionChanged(const SDL_ResizeEvent& resizeInfo); |
---|
60 | |
---|
61 | static void enter2DMode(); |
---|
62 | static void leave2DMode(); |
---|
63 | |
---|
64 | void wireframe(); |
---|
65 | |
---|
66 | static void storeMatrices(); |
---|
67 | static GLdouble modMat[16]; |
---|
68 | static GLdouble projMat[16]; |
---|
69 | static GLint viewPort[4]; |
---|
70 | |
---|
71 | void update(float dt); |
---|
72 | void tick(float dt); |
---|
73 | |
---|
74 | void drawBackgroundElements() const; |
---|
75 | void draw() const; |
---|
76 | void toggleFPSdisplay(); |
---|
77 | void displayFPS(bool display); |
---|
78 | |
---|
79 | void listModes(); |
---|
80 | bool hwSupportsEXT(const std::string& extension); |
---|
81 | |
---|
82 | /** @brief swaps the GL_BUFFERS */ |
---|
83 | inline static void swapBuffers() { SDL_GL_SwapBuffers(); }; |
---|
84 | |
---|
85 | void process(const Event &event); |
---|
86 | |
---|
87 | void loadGraphicsEffects(const TiXmlElement* root); |
---|
88 | |
---|
89 | |
---|
90 | |
---|
91 | private: |
---|
92 | GraphicsEngine(); |
---|
93 | int initVideo(unsigned int resX, unsigned int resY, unsigned int bbp); |
---|
94 | void setGLattribs(); |
---|
95 | void grabHardwareSettings(); |
---|
96 | |
---|
97 | public: |
---|
98 | |
---|
99 | private: |
---|
100 | static GraphicsEngine* singletonRef; //!< Pointer to the only instance of this Class |
---|
101 | bool isInit; //!< if the GraphicsEngine is initialized. |
---|
102 | |
---|
103 | // state. |
---|
104 | SDL_Surface* screen; //!< the screen we draw to |
---|
105 | int resolutionX; //!< the X-resoultion of the screen |
---|
106 | int resolutionY; //!< the Y-resolution of the screen |
---|
107 | int bitsPerPixel; //!< the bits per pixels of the screen |
---|
108 | Uint32 fullscreenFlag; //!< if we are in fullscreen mode |
---|
109 | Uint32 videoFlags; //!< flags for video |
---|
110 | SDL_Rect** videoModes; //!< list of resolutions |
---|
111 | |
---|
112 | bool fogEnabled; //!< If Fog should be enabled. |
---|
113 | bool shadowsEnabled; //!< If Shadows should be enabled. |
---|
114 | bool particlesEnabled; //!< If particles should be enabled. |
---|
115 | bool bAntialiasing; //!< true if antialiasing enabled |
---|
116 | |
---|
117 | int particlesValue; //!< How many particles |
---|
118 | int textureQuality; //!< the quality of Textures |
---|
119 | int filteringMethod; //!< The filtering Method of textures. |
---|
120 | int modelQuality; //!< The quality of the Models loaded. |
---|
121 | int antialiasingDepth; //!< the Depth of the AntiAlias-Filter. |
---|
122 | |
---|
123 | // HARDWARE-Settings: |
---|
124 | std::string hwRenderer; //!< HW-renderer-string |
---|
125 | std::string hwVendor; //!< HW-vendor-string |
---|
126 | std::string hwVersion; //!< HW-version-string |
---|
127 | SubString hwExtensions; //!< All suported Extensions. |
---|
128 | |
---|
129 | // FPS-related |
---|
130 | bool bDisplayFPS; //!< is true if the fps should be displayed |
---|
131 | float currentFPS; //!< the current frame rate: frames per seconds |
---|
132 | float maxFPS; //!< maximal frame rate we ever got since start of the game |
---|
133 | float minFPS; //!< minimal frame rate we ever got since start. |
---|
134 | |
---|
135 | const std::list<BaseObject*>* graphicsEffects; //!< list of graphics effects |
---|
136 | |
---|
137 | |
---|
138 | #ifndef NO_TEXT |
---|
139 | Text* geTextCFPS; //!< Text for the current FPS |
---|
140 | Text* geTextMaxFPS; //!< Text for the max FPS |
---|
141 | Text* geTextMinFPS; //!< Text for the min FPS |
---|
142 | #endif /* NO_TEXT */ |
---|
143 | }; |
---|
144 | |
---|
145 | #endif /* _GRAPHICS_ENGINE_H */ |
---|