Browse Source

Prepared to add glut

Thomas Buck 10 years ago
parent
commit
4836137bc6
4 changed files with 176 additions and 7 deletions
  1. 53
    0
      include/WindowGLUT.h
  2. 22
    7
      src/CMakeLists.txt
  3. 97
    0
      src/WindowGLUT.cpp
  4. 4
    0
      src/main.cpp

+ 53
- 0
include/WindowGLUT.h View File

@@ -0,0 +1,53 @@
1
+/*!
2
+ * \file include/WindowGLUT.h
3
+ * \brief GLUT windowing implementation
4
+ *
5
+ * \author xythobuz
6
+ */
7
+
8
+#ifndef _WINDOW_GLUT_H_
9
+#define _WINDOW_GLUT_H_
10
+
11
+#include "Window.h"
12
+
13
+/*!
14
+ * \brief GLUT windowing implementation
15
+ */
16
+class WindowGLUT : public Window {
17
+public:
18
+
19
+    /*!
20
+     * \brief Constructs an object of WindowGLUT
21
+     */
22
+    WindowGLUT();
23
+
24
+    /*!
25
+     * \brief Deconstructs an object of WindowGLUT
26
+     */
27
+    virtual ~WindowGLUT();
28
+
29
+    virtual void setSize(unsigned int width, unsigned int height);
30
+
31
+    virtual void setFullscreen(bool fullscreen);
32
+
33
+    virtual void setMousegrab(bool grab);
34
+
35
+    virtual bool getMousegrab();
36
+
37
+    virtual int initialize();
38
+
39
+    virtual void eventHandling();
40
+
41
+    virtual void setTextInput(bool on);
42
+
43
+    virtual bool getTextInput();
44
+
45
+    virtual void delay(unsigned int ms);
46
+
47
+    virtual void swapBuffersGL();
48
+
49
+private:
50
+};
51
+
52
+#endif
53
+

+ 22
- 7
src/CMakeLists.txt View File

@@ -1,3 +1,7 @@
1
+# Options
2
+option (ENABLE_AUDIO "Enable Sound Output" YES)
3
+option (FORCE_GLUT "Use freeGLUT even if SDL2 was found" NO)
4
+
1 5
 # Add OpenGL Library
2 6
 find_package (OpenGL REQUIRED)
3 7
 include_directories (SYSTEM ${OPENGL_INCLUDE_DIRS})
@@ -10,7 +14,7 @@ set (LIBS ${LIBS} ${ZLIB_LIBRARIES})
10 14
 
11 15
 # Add SDL2 Library
12 16
 find_package (SDL2)
13
-if (SDL2_FOUND)
17
+if (SDL2_FOUND AND NOT FORCE_GLUT)
14 18
     include_directories (SYSTEM ${SDL2_INCLUDE_DIR})
15 19
     set (LIBS ${LIBS} ${SDL2_LIBRARY})
16 20
 
@@ -20,7 +24,14 @@ if (SDL2_FOUND)
20 24
         include_directories (SYSTEM ${SDL2TTF_INCLUDE_DIR})
21 25
         set (LIBS ${LIBS} ${SDL2TTF_LIBRARY})
22 26
     endif (SDL2TTF_FOUND)
23
-endif (SDL2_FOUND)
27
+else (SDL2_FOUND AND NOT FORCE_GLUT)
28
+    # Add freeglut Library
29
+    find_package (GLUT)
30
+    if (GLUT_FOUND)
31
+        include_directories (SYSTEM ${GLUT_INCLUDE_DIR})
32
+        set (LIBS ${LIBS} ${GLUT_LIBRARY})
33
+    endif (GLUT_FOUND)
34
+endif (SDL2_FOUND AND NOT FORCE_GLUT)
24 35
 
25 36
 # Add OpenAL Library
26 37
 find_package (OpenAL)
@@ -77,7 +88,6 @@ set (SRCS ${SRCS} "Window.cpp")
77 88
 set (SRCS ${SRCS} "World.cpp")
78 89
 
79 90
 # Select available Sound library
80
-option (ENABLE_AUDIO "Enable Sound Output" YES)
81 91
 if (OPENAL_FOUND AND ALUT_FOUND AND ENABLE_AUDIO)
82 92
     set (SRCS ${SRCS} "SoundAL.cpp")
83 93
     set (USING_AL TRUE)
@@ -88,16 +98,21 @@ else (OPENAL_FOUND AND ALUT_FOUND AND ENABLE_AUDIO)
88 98
 endif (OPENAL_FOUND AND ALUT_FOUND AND ENABLE_AUDIO)
89 99
 
90 100
 # Select available Windowing library
91
-if (SDL2_FOUND)
101
+if (SDL2_FOUND AND NOT FORCE_GLUT)
92 102
     set (SRCS ${SRCS} "WindowSDL.cpp")
93 103
     set (OpenRaider_CXX_FLAGS "${OpenRaider_CXX_FLAGS} -DUSING_SDL")
94 104
     if (SDL2TTF_FOUND)
95 105
         set (SRCS ${SRCS} "FontSDL.cpp")
96 106
         set (OpenRaider_CXX_FLAGS "${OpenRaider_CXX_FLAGS} -DUSING_SDL_FONT")
97 107
     endif (SDL2TTF_FOUND)
98
-else (SDL2_FOUND)
99
-    message (FATAL_ERROR "SDL2 is required at the moment!")
100
-endif (SDL2_FOUND)
108
+else (SDL2_FOUND AND NOT FORCE_GLUT)
109
+    if (GLUT_FOUND)
110
+        set (SRCS ${SRCS} "WindowGLUT.cpp")
111
+        set (OpenRaider_CXX_FLAGS "${OpenRaider_CXX_FLAGS} -DUSING_GLUT")
112
+    else (GLUT_FOUND)
113
+        message (FATAL_ERROR "SDL2 or freeGLUT are required!")
114
+    endif (GLUT_FOUND)
115
+endif (SDL2_FOUND AND NOT FORCE_GLUT)
101 116
 
102 117
 if (PNG_FOUND)
103 118
     set (USING_PNG TRUE)

+ 97
- 0
src/WindowGLUT.cpp View File

@@ -0,0 +1,97 @@
1
+/*!
2
+ * \file src/WindowGLUT.cpp
3
+ * \brief GLUT windowing implementation
4
+ *
5
+ * \author xythobuz
6
+ */
7
+
8
+#include <cstdio>
9
+#include <ctime>
10
+
11
+#include "global.h"
12
+#include "RunTime.h"
13
+#include "UI.h"
14
+#include "utils/strings.h"
15
+#include "WindowGLUT.h"
16
+
17
+WindowGLUT::WindowGLUT() {
18
+    mInit = false;
19
+    mWidth = DEFAULT_WIDTH;
20
+    mHeight = DEFAULT_HEIGHT;
21
+    mFullscreen = false;
22
+    mMousegrab = false;
23
+    mTextInput = false;
24
+}
25
+
26
+WindowGLUT::~WindowGLUT() {
27
+    if (mInit) {
28
+    }
29
+}
30
+
31
+void WindowGLUT::setSize(unsigned int width, unsigned int height) {
32
+    assert(width > 0);
33
+    assert(height > 0);
34
+
35
+    mWidth = width;
36
+    mHeight = height;
37
+
38
+    if (mInit == true) {
39
+        resizeGL();
40
+    }
41
+}
42
+
43
+void WindowGLUT::setFullscreen(bool fullscreen) {
44
+    mFullscreen = fullscreen;
45
+
46
+    if (mInit == true) {
47
+    }
48
+}
49
+
50
+void WindowGLUT::setMousegrab(bool grab) {
51
+    mMousegrab = grab;
52
+
53
+    if (mInit == true) {
54
+    }
55
+}
56
+
57
+bool WindowGLUT::getMousegrab() {
58
+    return mMousegrab;
59
+}
60
+
61
+int WindowGLUT::initialize() {
62
+    assert(mInit == false);
63
+
64
+
65
+    mInit = true;
66
+
67
+
68
+    return 0;
69
+}
70
+
71
+void WindowGLUT::eventHandling() {
72
+    assert(mInit == true);
73
+
74
+
75
+
76
+    UI::eventsFinished();
77
+}
78
+
79
+void WindowGLUT::setTextInput(bool on) {
80
+    assert(mInit == true);
81
+
82
+    mTextInput = on;
83
+}
84
+
85
+bool WindowGLUT::getTextInput() {
86
+    assert(mInit == true);
87
+    return mTextInput;
88
+}
89
+
90
+void WindowGLUT::delay(unsigned int ms) {
91
+    assert(mInit == true);
92
+}
93
+
94
+void WindowGLUT::swapBuffersGL() {
95
+    assert(mInit == true);
96
+}
97
+

+ 4
- 0
src/main.cpp View File

@@ -37,6 +37,8 @@
37 37
 
38 38
 #ifdef USING_SDL
39 39
 #include "WindowSDL.h"
40
+#elif defined(USING_GLUT)
41
+#include "WindowGLUT.h"
40 42
 #else
41 43
 #error No Windowing Library selected!
42 44
 #endif
@@ -129,6 +131,8 @@ int main(int argc, char* argv[]) {
129 131
 
130 132
 #ifdef USING_SDL
131 133
     gWindow.reset(new WindowSDL());
134
+#elif defined(USING_GLUT)
135
+    gWindow.reset(new WindowGLUT());
132 136
 #endif
133 137
 
134 138
     Command::fillCommandList();

Loading…
Cancel
Save