4 #include "client/client_config.h"
5 #include "client/debug_menu.h"
6 #include "client/game.h"
7 #include "client/gui.h"
8 #include "client/input.h"
9 #include "client/scene.h"
10 #include "client/window.h"
15 static void framebuffer_size_callback(unused GLFWwindow *handle, int width, int height)
17 glViewport(0, 0, width, height);
19 if (! window.fullscreen) {
20 window.small_bounds.width = width;
21 window.small_bounds.height = height;
24 scene_on_resize(width, height);
25 gui_on_resize(width, height);
26 game_on_resize(width, height);
29 static void cursor_pos_callback(unused GLFWwindow *handle, double current_x, double current_y)
31 input_on_cursor_pos(current_x, current_y);
34 static void window_pos_callback(unused GLFWwindow *handle, int x, int y)
36 if (! window.fullscreen) {
37 window.small_bounds.x = x;
38 window.small_bounds.y = y;
42 void window_enter_fullscreen()
44 window.fullscreen = true;
45 GLFWmonitor *monitor = glfwGetPrimaryMonitor();
46 const GLFWvidmode *vidmode = glfwGetVideoMode(monitor);
47 glfwSetWindowMonitor(window.handle, monitor, 0, 0, vidmode->width, vidmode->height, 0);
49 debug_menu_update_fullscreen();
52 void window_exit_fullscreen()
54 window.fullscreen = false;
55 glfwSetWindowMonitor(window.handle, NULL, window.small_bounds.x, window.small_bounds.y, window.small_bounds.width, window.small_bounds.height, 0);
57 debug_menu_update_fullscreen();
60 bool window_init(int width, int height)
63 fprintf(stderr, "Failed to initialize GLFW\n");
67 glfwWindowHint(GLFW_SAMPLES, client_config.antialiasing);
68 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
69 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
70 glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
72 window.handle = glfwCreateWindow(width, height, "Dragonblocks", NULL, NULL);
74 window.small_bounds.width = width;
75 window.small_bounds.height = height;
77 if (! window.handle) {
78 fprintf(stderr, "Failed to create window\n");
83 glfwMakeContextCurrent(window.handle);
85 if (glewInit() != GLEW_OK) {
86 fprintf(stderr, "Failed to initialize GLEW\n");
90 glfwSetFramebufferSizeCallback(window.handle, &framebuffer_size_callback);
91 glfwSetCursorPosCallback(window.handle, &cursor_pos_callback);
92 glfwSetWindowPosCallback(window.handle, &window_pos_callback);