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/window.h"
13 static int small_x, small_y, small_width, small_height;
15 static void update_projection()
17 mat4x4_perspective(window.projection,
18 window.fov / 180.0f * M_PI,
19 (float) window.width / (float) window.height,
20 0.01f, client_config.view_distance + 28.0f);
23 static void framebuffer_size_callback(__attribute__((unused)) GLFWwindow *handle, int width, int height)
25 glViewport(0, 0, width, height);
27 window.height = height;
29 if (!window.fullscreen) {
31 small_height = height;
35 gui_update_projection();
38 static void cursor_pos_callback(__attribute__((unused)) GLFWwindow *handle, double x, double y)
43 static void window_pos_callback(__attribute__((unused)) GLFWwindow *handle, int x, int y)
45 if (!window.fullscreen) {
51 void window_enter_fullscreen()
53 window.fullscreen = true;
54 GLFWmonitor *monitor = glfwGetPrimaryMonitor();
55 const GLFWvidmode *vidmode = glfwGetVideoMode(monitor);
56 glfwSetWindowMonitor(window.handle, monitor, 0, 0, vidmode->width, vidmode->height, 0);
58 debug_menu_changed(ENTRY_FULLSCREEN);
61 void window_exit_fullscreen()
63 window.fullscreen = false;
64 glfwSetWindowMonitor(window.handle, NULL, small_x, small_y, small_width, small_height, 0);
66 debug_menu_changed(ENTRY_FULLSCREEN);
72 fprintf(stderr, "[error] failed to initialize GLFW\n");
76 glfwWindowHint(GLFW_SAMPLES, client_config.antialiasing);
77 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
78 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
79 glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
83 window.handle = glfwCreateWindow(window.width, window.height, "Dragonblocks", NULL, NULL);
84 window.fullscreen = false;
88 small_width = window.width;
89 small_height = window.height;
92 fprintf(stderr, "[error] failed to create window\n");
97 glfwMakeContextCurrent(window.handle);
99 if (!client_config.vsync)
102 if (glewInit() != GLEW_OK) {
103 fprintf(stderr, "[error] failed to initialize GLEW\n");
107 glfwSetFramebufferSizeCallback(window.handle, &framebuffer_size_callback);
108 glfwSetCursorPosCallback(window.handle, &cursor_pos_callback);
109 glfwSetWindowPosCallback(window.handle, &window_pos_callback);