Changeset d8cb15e in opengl-game
- Timestamp:
- Aug 30, 2019, 7:30:53 PM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 5529ab5
- Parents:
- d5f2b42
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
game-gui-glfw.cpp
rd5f2b42 rd8cb15e 1 1 #include "game-gui-glfw.hpp" 2 2 3 string GameGui_GLFW::s_errorMessage; 4 5 void glfw_error_callback(int error, const char* description) { 6 GameGui_GLFW::s_errorMessage = description; 7 } 8 9 string& GameGui_GLFW::GetError() { 10 return GameGui_GLFW::s_errorMessage; 11 } 12 3 13 bool GameGui_GLFW::Init() { 4 return glfwInit() == GLFW_TRUE ? RTWO_SUCCESS : RTWO_SUCCESS; 14 GameGui_GLFW::s_errorMessage = "No error"; 15 glfwSetErrorCallback(glfw_error_callback); 16 17 return glfwInit() == GLFW_TRUE ? RTWO_SUCCESS : RTWO_ERROR; 5 18 } 6 19 -
game-gui-glfw.hpp
rd5f2b42 rd8cb15e 12 12 class GameGui_GLFW : public GameGui { 13 13 public: 14 string& GetError(); 15 16 static string s_errorMessage; // Has to be public so that glfw_error_callback can access it 17 14 18 bool Init(); 15 19 void Shutdown(); … … 29 33 }; 30 34 35 void glfw_error_callback(int error, const char* description); 36 31 37 #endif // _GAME_GUI_GLFW_H -
makefile
rd5f2b42 rd8cb15e 25 25 $(CC) $^ $(DEP) $(CFLAGS) -o $@ 26 26 27 openglgame: main-opengl.cpp opengl-game.cpp 27 openglgame: main-opengl.cpp opengl-game.cpp game-gui-glfw.cpp 28 28 $(CC) $^ $(DEP) $(CFLAGS) -o $@ 29 29 -
opengl-game.cpp
rd5f2b42 rd8cb15e 3 3 #include <iostream> 4 4 5 #include "game-gui-glfw.hpp" 6 5 7 using namespace std; 6 8 7 9 OpenGLGame::OpenGLGame() { 10 gui = nullptr; 11 window = nullptr; 8 12 } 9 13 … … 12 16 13 17 void OpenGLGame::run() { 14 cout << "Running like a boss!" << endl; 18 if (initWindow() == RTWO_ERROR) { 19 return; 20 } 21 initOpenGL(); 22 mainLoop(); 23 cleanup(); 15 24 } 25 26 bool OpenGLGame::initWindow() { 27 gui = new GameGui_GLFW(); 28 29 if (gui->Init() == RTWO_ERROR) { 30 cout << "UI library could not be initialized!" << endl; 31 cout << gui->GetError() << endl; 32 return RTWO_ERROR; 33 } 34 cout << "GUI init succeeded" << endl; 35 36 window = (GLFWwindow*) gui->CreateWindow("OpenGL Game", SCREEN_WIDTH, SCREEN_HEIGHT); 37 if (window == nullptr) { 38 cout << "Window could not be created!" << endl; 39 return RTWO_ERROR; 40 } 41 42 return RTWO_SUCCESS; 43 } 44 45 void OpenGLGame::initOpenGL() { 46 } 47 48 void OpenGLGame::mainLoop() { 49 while (!glfwWindowShouldClose(window)) { 50 glfwPollEvents(); 51 52 glfwSwapBuffers(window); 53 } 54 } 55 56 void OpenGLGame::cleanup() { 57 gui->DestroyWindow(); 58 gui->Shutdown(); 59 delete gui; 60 } -
opengl-game.hpp
rd5f2b42 rd8cb15e 3 3 4 4 #include "game-gui-glfw.hpp" 5 6 const int SCREEN_WIDTH = 800; 7 const int SCREEN_HEIGHT = 600; 5 8 6 9 class OpenGLGame { … … 12 15 13 16 private: 17 GameGui* gui; 18 GLFWwindow* window; 19 20 bool initWindow(); 21 void initOpenGL(); 22 void mainLoop(); 23 void cleanup(); 14 24 }; 15 25
Note:
See TracChangeset
for help on using the changeset viewer.