mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-04-10 06:14:07 +08:00
feat: add fullscreen support
This commit is contained in:
@@ -10,7 +10,7 @@ public:
|
||||
GLFWwindow* get_glfw_window();
|
||||
void init();
|
||||
void update_viewport();
|
||||
|
||||
void toggle_fullscreen();
|
||||
private:
|
||||
float m_aspect;
|
||||
GLFWwindow* m_window;
|
||||
|
||||
11
src/app.cpp
11
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<App*>(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<App*>(glfwGetWindowUserPointer(window));
|
||||
CUBED_ASSERT_MSG(app, "nullptr");
|
||||
|
||||
app->m_world.get_player("TestPlayer").update_player_move_state(key, action);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<int>(mode->width / 2.0f) - 400, static_cast<int>(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();
|
||||
}
|
||||
Reference in New Issue
Block a user