Przeglądaj źródła

Prepared to add glut

Thomas Buck 10 lat temu
rodzic
commit
4836137bc6
4 zmienionych plików z 176 dodań i 7 usunięć
  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 Wyświetl plik

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 Wyświetl plik

1
+# Options
2
+option (ENABLE_AUDIO "Enable Sound Output" YES)
3
+option (FORCE_GLUT "Use freeGLUT even if SDL2 was found" NO)
4
+
1
 # Add OpenGL Library
5
 # Add OpenGL Library
2
 find_package (OpenGL REQUIRED)
6
 find_package (OpenGL REQUIRED)
3
 include_directories (SYSTEM ${OPENGL_INCLUDE_DIRS})
7
 include_directories (SYSTEM ${OPENGL_INCLUDE_DIRS})
10
 
14
 
11
 # Add SDL2 Library
15
 # Add SDL2 Library
12
 find_package (SDL2)
16
 find_package (SDL2)
13
-if (SDL2_FOUND)
17
+if (SDL2_FOUND AND NOT FORCE_GLUT)
14
     include_directories (SYSTEM ${SDL2_INCLUDE_DIR})
18
     include_directories (SYSTEM ${SDL2_INCLUDE_DIR})
15
     set (LIBS ${LIBS} ${SDL2_LIBRARY})
19
     set (LIBS ${LIBS} ${SDL2_LIBRARY})
16
 
20
 
20
         include_directories (SYSTEM ${SDL2TTF_INCLUDE_DIR})
24
         include_directories (SYSTEM ${SDL2TTF_INCLUDE_DIR})
21
         set (LIBS ${LIBS} ${SDL2TTF_LIBRARY})
25
         set (LIBS ${LIBS} ${SDL2TTF_LIBRARY})
22
     endif (SDL2TTF_FOUND)
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
 # Add OpenAL Library
36
 # Add OpenAL Library
26
 find_package (OpenAL)
37
 find_package (OpenAL)
77
 set (SRCS ${SRCS} "World.cpp")
88
 set (SRCS ${SRCS} "World.cpp")
78
 
89
 
79
 # Select available Sound library
90
 # Select available Sound library
80
-option (ENABLE_AUDIO "Enable Sound Output" YES)
81
 if (OPENAL_FOUND AND ALUT_FOUND AND ENABLE_AUDIO)
91
 if (OPENAL_FOUND AND ALUT_FOUND AND ENABLE_AUDIO)
82
     set (SRCS ${SRCS} "SoundAL.cpp")
92
     set (SRCS ${SRCS} "SoundAL.cpp")
83
     set (USING_AL TRUE)
93
     set (USING_AL TRUE)
88
 endif (OPENAL_FOUND AND ALUT_FOUND AND ENABLE_AUDIO)
98
 endif (OPENAL_FOUND AND ALUT_FOUND AND ENABLE_AUDIO)
89
 
99
 
90
 # Select available Windowing library
100
 # Select available Windowing library
91
-if (SDL2_FOUND)
101
+if (SDL2_FOUND AND NOT FORCE_GLUT)
92
     set (SRCS ${SRCS} "WindowSDL.cpp")
102
     set (SRCS ${SRCS} "WindowSDL.cpp")
93
     set (OpenRaider_CXX_FLAGS "${OpenRaider_CXX_FLAGS} -DUSING_SDL")
103
     set (OpenRaider_CXX_FLAGS "${OpenRaider_CXX_FLAGS} -DUSING_SDL")
94
     if (SDL2TTF_FOUND)
104
     if (SDL2TTF_FOUND)
95
         set (SRCS ${SRCS} "FontSDL.cpp")
105
         set (SRCS ${SRCS} "FontSDL.cpp")
96
         set (OpenRaider_CXX_FLAGS "${OpenRaider_CXX_FLAGS} -DUSING_SDL_FONT")
106
         set (OpenRaider_CXX_FLAGS "${OpenRaider_CXX_FLAGS} -DUSING_SDL_FONT")
97
     endif (SDL2TTF_FOUND)
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
 if (PNG_FOUND)
117
 if (PNG_FOUND)
103
     set (USING_PNG TRUE)
118
     set (USING_PNG TRUE)

+ 97
- 0
src/WindowGLUT.cpp Wyświetl plik

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 Wyświetl plik

37
 
37
 
38
 #ifdef USING_SDL
38
 #ifdef USING_SDL
39
 #include "WindowSDL.h"
39
 #include "WindowSDL.h"
40
+#elif defined(USING_GLUT)
41
+#include "WindowGLUT.h"
40
 #else
42
 #else
41
 #error No Windowing Library selected!
43
 #error No Windowing Library selected!
42
 #endif
44
 #endif
129
 
131
 
130
 #ifdef USING_SDL
132
 #ifdef USING_SDL
131
     gWindow.reset(new WindowSDL());
133
     gWindow.reset(new WindowSDL());
134
+#elif defined(USING_GLUT)
135
+    gWindow.reset(new WindowGLUT());
132
 #endif
136
 #endif
133
 
137
 
134
     Command::fillCommandList();
138
     Command::fillCommandList();

Ładowanie…
Anuluj
Zapisz