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 | |
---|
17 | // Forward Declaration |
---|
18 | class Text; |
---|
19 | class IniParser; |
---|
20 | |
---|
21 | //! class to handle graphics |
---|
22 | /** |
---|
23 | handles graphical SDL-initialisation, textures, resolutions, and so on |
---|
24 | */ |
---|
25 | class GraphicsEngine : public EventListener |
---|
26 | { |
---|
27 | public: |
---|
28 | virtual ~GraphicsEngine(); |
---|
29 | /** @returns a Pointer to the only object of this Class */ |
---|
30 | inline static GraphicsEngine* getInstance() { if (!singletonRef) singletonRef = new GraphicsEngine(); return singletonRef; }; |
---|
31 | |
---|
32 | int init(); |
---|
33 | int initFromIniFile(IniParser* iniParser); |
---|
34 | |
---|
35 | void setWindowName(const char* windowName, const char* icon); |
---|
36 | |
---|
37 | int setResolution(int width, int height, int bpp); |
---|
38 | void setFullscreen(bool fullscreen = false); |
---|
39 | static void setBackgroundColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha = 1.0); |
---|
40 | |
---|
41 | |
---|
42 | /** @returns the x resolution */ |
---|
43 | inline int getResolutionX() const { return this->resolutionX; }; |
---|
44 | /** @returns the y resolution */ |
---|
45 | inline int getResolutionY() const { return this->resolutionY; }; |
---|
46 | /** @returns the Bits Per Pixel */ |
---|
47 | inline int getbbp() const { return this->bitsPerPixel; }; |
---|
48 | |
---|
49 | int resolutionChanged(const SDL_ResizeEvent& resizeInfo); |
---|
50 | |
---|
51 | static void showMouse(bool show); |
---|
52 | static bool isMouseVisible(); |
---|
53 | static void stealWMEvents(bool steal); |
---|
54 | static bool isStealingEvents(); |
---|
55 | |
---|
56 | static void enter2DMode(); |
---|
57 | static void leave2DMode(); |
---|
58 | |
---|
59 | static void storeMatrices(); |
---|
60 | static GLdouble modMat[16]; |
---|
61 | static GLdouble projMat[16]; |
---|
62 | static GLint viewPort[4]; |
---|
63 | |
---|
64 | void tick(float dt); |
---|
65 | void draw() const; |
---|
66 | void displayFPS(bool display); |
---|
67 | |
---|
68 | void listModes(); |
---|
69 | |
---|
70 | /** \brief swaps the GL_BUFFERS */ |
---|
71 | inline static void swapBuffers() { SDL_GL_SwapBuffers(); }; |
---|
72 | |
---|
73 | void process(const Event &event); |
---|
74 | |
---|
75 | private: |
---|
76 | GraphicsEngine(); |
---|
77 | int initVideo(unsigned int resX, unsigned int resY, unsigned int bbp); |
---|
78 | int setGLattribs(); |
---|
79 | |
---|
80 | public: |
---|
81 | static bool texturesEnabled; //!< if textures should be enabled (globally) |
---|
82 | |
---|
83 | |
---|
84 | private: |
---|
85 | static GraphicsEngine* singletonRef; //!< Pointer to the only instance of this Class |
---|
86 | bool isInit; //!< if the GraphicsEngine is initialized. |
---|
87 | |
---|
88 | SDL_Surface* screen; //!< the screen we draw to |
---|
89 | int resolutionX; //!< the X-resoultion of the screen |
---|
90 | int resolutionY; //!< the Y-resolution of the screen |
---|
91 | int bitsPerPixel; //!< the bits per pixels of the screen |
---|
92 | Uint32 fullscreenFlag; //!< if we are in fullscreen mode |
---|
93 | Uint32 videoFlags; //!< flags for video |
---|
94 | SDL_Rect** videoModes; //!< list of resolutions |
---|
95 | |
---|
96 | bool bDisplayFPS; //!< is true if the fps should be displayed |
---|
97 | float currentFPS; //!< the current frame rate: frames per seconds |
---|
98 | float maxFPS; //!< maximal frame rate we ever got since start of the game |
---|
99 | float minFPS; //!< minimal frame rate we ever got since start |
---|
100 | |
---|
101 | |
---|
102 | #ifndef NO_TEXT |
---|
103 | Text* geTextCFPS; //!< Text for the current FPS |
---|
104 | Text* geTextMaxFPS; //!< Text for the max FPS |
---|
105 | Text* geTextMinFPS; //!< Text for the min FPS |
---|
106 | #endif /* NO_TEXT */ |
---|
107 | }; |
---|
108 | |
---|
109 | #endif /* _GRAPHICS_ENGINE_H */ |
---|