diff --git a/include/Cubed/window.hpp b/include/Cubed/window.hpp index e387f12..ea05211 100644 --- a/include/Cubed/window.hpp +++ b/include/Cubed/window.hpp @@ -10,7 +10,7 @@ public: GLFWwindow* get_glfw_window(); void init(); void update_viewport(); - + void toggle_fullscreen(); private: float m_aspect; GLFWwindow* m_window; diff --git a/src/app.cpp b/src/app.cpp index e599bbf..6b6a527 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -40,6 +40,9 @@ void App::init() { } void App::key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) { + App* app = static_cast(glfwGetWindowUserPointer(window)); + CUBED_ASSERT_MSG(app, "nullptr"); + switch(key) { case GLFW_KEY_Q: if (action == GLFW_PRESS) { @@ -55,10 +58,14 @@ void App::key_callback(GLFWwindow* window, int key, int scancode, int action, in if (action == GLFW_PRESS) { glfwSetWindowShouldClose(window, GLFW_TRUE); } + case GLFW_KEY_F11: + if (action == GLFW_PRESS) { + app->m_window.toggle_fullscreen(); + } + break; } - App* app = static_cast(glfwGetWindowUserPointer(window)); - CUBED_ASSERT_MSG(app, "nullptr"); + app->m_world.get_player("TestPlayer").update_player_move_state(key, action); } diff --git a/src/window.cpp b/src/window.cpp index 6be3714..7c684f0 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -39,19 +39,58 @@ void Window::init() { glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6); + glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); m_window = glfwCreateWindow(800, 600, "Cubed", NULL, NULL); + glfwMakeContextCurrent(m_window); glfwSwapInterval(1); - glfwSetInputMode(m_window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); if (glfwRawMouseMotionSupported()) { glfwSetInputMode(m_window, GLFW_RAW_MOUSE_MOTION, GLFW_TRUE); } else { LOG::warn("Don,t support Raw Mouse Motion"); } - + + GLFWmonitor* primary = glfwGetPrimaryMonitor(); + const GLFWvidmode* mode = glfwGetVideoMode(primary); + glfwSetWindowPos(m_window, static_cast(mode->width / 2.0f) - 400, static_cast(mode->height / 2.0f) - 300); //update_viewport(); +} + +void Window::toggle_fullscreen() { + static int windowed_xpos = 0, windowed_ypos = 0; + static int windowed_width = 800, windowed_height = 600; + + GLFWmonitor* monitor = glfwGetWindowMonitor(m_window); + if (monitor != nullptr) { + glfwSetWindowMonitor( + m_window, + nullptr, + windowed_xpos, + windowed_ypos, + windowed_width, + windowed_height, + 0 + ); + } else { + glfwGetWindowPos(m_window, &windowed_xpos, &windowed_ypos); + glfwGetWindowSize(m_window, &windowed_width, &windowed_height); + + GLFWmonitor* primary = glfwGetPrimaryMonitor(); + const GLFWvidmode* mode = glfwGetVideoMode(primary); + + glfwSetWindowMonitor( + m_window, + primary, + 0, + 0, + mode->width, + mode->height, + GL_DONT_CARE + ); + } + update_viewport(); } \ No newline at end of file