Changeset 1ce9afe in opengl-game for game-gui-glfw.cpp
- Timestamp:
- Sep 2, 2019, 7:40:49 PM (6 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 7fc5e27
- Parents:
- 301d0d4
- File:
-
- 1 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 }
Note:
See TracChangeset
for help on using the changeset viewer.