4 #include "client/debug_menu.h"
5 #include "client/game.h"
6 #include "client/gui.h"
7 #include "client/input.h"
8 #include "client/scene.h"
9 #include "client/window.h"
14 static void framebuffer_size_callback(unused GLFWwindow *handle, int width, int height)
16 glViewport(0, 0, width, height);
18 if (! window.fullscreen) {
19 window.small_bounds.width = width;
20 window.small_bounds.height = height;
23 scene_on_resize(width, height);
24 gui_on_resize(width, height);
25 game_on_resize(width, height);
28 static void cursor_pos_callback(unused GLFWwindow *handle, double current_x, double current_y)
30 input_on_cursor_pos(current_x, current_y);
33 static void window_pos_callback(unused GLFWwindow *handle, int x, int y)
35 if (! window.fullscreen) {
36 window.small_bounds.x = x;
37 window.small_bounds.y = y;
41 void window_enter_fullscreen()
43 window.fullscreen = true;
44 GLFWmonitor *monitor = glfwGetPrimaryMonitor();
45 const GLFWvidmode *vidmode = glfwGetVideoMode(monitor);
46 glfwSetWindowMonitor(window.handle, monitor, 0, 0, vidmode->width, vidmode->height, 0);
48 debug_menu_update_fullscreen();
51 void window_exit_fullscreen()
53 window.fullscreen = false;
54 glfwSetWindowMonitor(window.handle, NULL, window.small_bounds.x, window.small_bounds.y, window.small_bounds.width, window.small_bounds.height, 0);
56 debug_menu_update_fullscreen();
59 bool window_init(int width, int height)
62 fprintf(stderr, "Failed to initialize GLFW\n");
66 glfwWindowHint(GLFW_SAMPLES, 8);
67 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
68 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);
69 glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
71 window.handle = glfwCreateWindow(width, height, "Dragonblocks", NULL, NULL);
73 window.small_bounds.width = width;
74 window.small_bounds.height = height;
76 if (! window.handle) {
77 fprintf(stderr, "Failed to create window\n");
82 glfwMakeContextCurrent(window.handle);
84 if (glewInit() != GLEW_OK) {
85 fprintf(stderr, "Failed to initialize GLEW\n");
89 glfwSetFramebufferSizeCallback(window.handle, &framebuffer_size_callback);
90 glfwSetCursorPosCallback(window.handle, &cursor_pos_callback);
91 glfwSetWindowPosCallback(window.handle, &window_pos_callback);