Changeset 1ce9afe in opengl-game
- Timestamp:
- Sep 2, 2019, 7:40:49 PM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 7fc5e27
- Parents:
- 301d0d4
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
game-gui-glfw.cpp
r301d0d4 r1ce9afe 1 1 #include "game-gui-glfw.hpp" 2 2 3 #include "compiler.hpp" 3 4 #include "consts.hpp" 5 6 const int KEY_STATE_UNCHANGED = -1; 4 7 5 8 string GameGui_GLFW::s_errorMessage; 6 9 7 void glfw_error_callback(int error, const char* description) { 8 GameGui_GLFW::s_errorMessage = description; 9 } 10 int GameGui_GLFW::s_keyState[NUM_KEYS]; 11 bool GameGui_GLFW::s_keyDown[NUM_KEYS]; 10 12 11 13 string& GameGui_GLFW::GetError() { … … 24 26 } 25 27 26 void* GameGui_GLFW::CreateWindow(const string& title, unsigned int width, unsigned int height) { 27 glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); 28 void* GameGui_GLFW::CreateWindow(const string& title, unsigned int width, unsigned int height, bool fullscreen) { 29 GLFWwindow* window = nullptr; 30 GLFWmonitor* mon = nullptr; 28 31 29 window = glfwCreateWindow(width, height, title.c_str(), nullptr, nullptr); 32 #if defined(GAMEGUI_INCLUDE_VULKAN) 33 glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); // This is for Vulkan, OpenGL needs different flags 34 #elif defined(MAC) 35 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); 36 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); 37 glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); 38 glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); 39 #else 40 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); 41 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); 42 #endif 43 44 glfwWindowHint(GLFW_SAMPLES, 16); 45 glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, true); 46 47 if (fullscreen) { 48 mon = glfwGetPrimaryMonitor(); 49 const GLFWvidmode* vmode = glfwGetVideoMode(mon); 50 51 width = vmode->width; 52 height = vmode->height; 53 54 // TODO: Should probably enable some way to retrieve this from outside this class 55 // and print it out there 56 cout << "Fullscreen resolution " << vmode->width << "x" << vmode->height << endl; 57 } 58 59 window = glfwCreateWindow(width, height, title.c_str(), mon, nullptr); 60 //glfwMakeContextCurrent(window); 61 62 //glfwSetMouseButtonCallback(window, mouse_button_callback); 63 glfwSetKeyCallback(window, glfw_key_callback); 64 65 fill(GameGui_GLFW::s_keyState, GameGui_GLFW::s_keyState + NUM_KEYS, KEY_STATE_UNCHANGED); 30 66 31 67 return window; … … 60 96 glfwGetFramebufferSize(window, width, height); 61 97 } 98 99 void glfw_error_callback(int error, const char* description) { 100 GameGui_GLFW::s_errorMessage = description; 101 } 102 103 void glfw_key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) { 104 GameGui_GLFW::s_keyState[key] = action; 105 106 // should be true for GLFW_PRESS and GLFW_REPEAT 107 GameGui_GLFW::s_keyDown[key] = (action != GLFW_RELEASE); 108 } -
game-gui-glfw.hpp
r301d0d4 r1ce9afe 10 10 #include <GLFW/glfw3.h> 11 11 12 #define NUM_KEYS (512) 13 12 14 class GameGui_GLFW : public GameGui { 13 15 public: 16 static string s_errorMessage; // Has to be public so that glfw_error_callback can access it 17 18 // Both have to be public so that glfw_key_callback can access them 19 // TODO: Implement a more generic public api over this to get the key state 20 static int s_keyState[NUM_KEYS]; 21 static bool s_keyDown[NUM_KEYS]; 22 14 23 string& GetError(); 15 16 static string s_errorMessage; // Has to be public so that glfw_error_callback can access it17 24 18 25 bool Init(); 19 26 void Shutdown(); 20 27 21 void* CreateWindow(const string& title, unsigned int width, unsigned int height );28 void* CreateWindow(const string& title, unsigned int width, unsigned int height, bool fullscreen); 22 29 void DestroyWindow(); 23 30 … … 34 41 35 42 void glfw_error_callback(int error, const char* description); 43 void glfw_key_callback(GLFWwindow* window, int key, int scancode, int action, int mods); 36 44 37 45 #endif // _GAME_GUI_GLFW_H -
game-gui-sdl.cpp
r301d0d4 r1ce9afe 37 37 } 38 38 39 void* GameGui_SDL::CreateWindow(const string& title, unsigned int width, unsigned int height) { 39 void* GameGui_SDL::CreateWindow(const string& title, unsigned int width, unsigned int height, bool fullscreen) { 40 cout << "About to go fullscreen in SDL..." << endl; 41 42 // TODO: Make an OpenGL version of the SDL_CreateWindow call as well 43 40 44 // On Apple's OS X you must set the NSHighResolutionCapable Info.plist property to YES, 41 45 // otherwise you will not receive a High DPI OpenGL canvas. -
game-gui-sdl.hpp
r301d0d4 r1ce9afe 16 16 void Shutdown(); 17 17 18 void* CreateWindow(const string& title, unsigned int width, unsigned int height );18 void* CreateWindow(const string& title, unsigned int width, unsigned int height, bool fullscreen); 19 19 void DestroyWindow(); 20 20 -
game-gui.hpp
r301d0d4 r1ce9afe 8 8 #include <vulkan/vulkan.h> 9 9 #endif 10 11 // TODO: Remove the line below once the couts in the game-gui-* files are moved 12 #include <iostream> 10 13 11 14 using namespace std; … … 20 23 virtual void Shutdown() = 0; 21 24 22 virtual void* CreateWindow(const string& title, unsigned int width, unsigned int height ) = 0;25 virtual void* CreateWindow(const string& title, unsigned int width, unsigned int height, bool fullscreen) = 0; 23 26 virtual void DestroyWindow() = 0; 24 27 -
opengl-game.cpp
r301d0d4 r1ce9afe 36 36 cout << "GUI init succeeded" << endl; 37 37 38 window = (GLFWwindow*) gui->CreateWindow("OpenGL Game", width, height );38 window = (GLFWwindow*) gui->CreateWindow("OpenGL Game", width, height, guiFlags | GUI_FLAGS_WINDOW_FULLSCREEN); 39 39 if (window == nullptr) { 40 40 cout << "Window could not be created!" << endl; … … 52 52 glfwPollEvents(); 53 53 54 if (GameGui_GLFW::s_keyState[GLFW_KEY_ESCAPE] == GLFW_PRESS) { 55 glfwSetWindowShouldClose(window, 1); 56 } 57 54 58 glfwSwapBuffers(window); 55 59 } -
vulkan-game.cpp
r301d0d4 r1ce9afe 37 37 cout << "GUI init succeeded" << endl; 38 38 39 window = (SDL_Window*) gui->CreateWindow("Vulkan Game", width, height );39 window = (SDL_Window*) gui->CreateWindow("Vulkan Game", width, height, guiFlags | GUI_FLAGS_WINDOW_FULLSCREEN); 40 40 if (window == nullptr) { 41 41 cout << "Window could not be created!" << endl;
Note:
See TracChangeset
for help on using the changeset viewer.