4 #include "client/client_config.h"
5 #include "client/debug_menu.h"
6 #include "client/game.h"
7 #include "client/gl_debug.h"
8 #include "client/gui.h"
9 #include "client/input.h"
10 #include "client/window.h"
14 static int small_x, small_y, small_width, small_height;
16 static void update_projection()
18 mat4x4_perspective(window.projection,
19 window.fov / 180.0f * M_PI,
20 (float) window.width / (float) window.height,
21 0.01f, client_config.view_distance + 28.0f);
24 static void framebuffer_size_callback(__attribute__((unused)) GLFWwindow *handle, int width, int height)
26 glViewport(0, 0, width, height); GL_DEBUG
28 window.height = height;
30 if (!window.fullscreen) {
32 small_height = height;
36 gui_update_projection();
39 static void cursor_pos_callback(__attribute__((unused)) GLFWwindow *handle, double x, double y)
44 static void window_pos_callback(__attribute__((unused)) GLFWwindow *handle, int x, int y)
46 if (!window.fullscreen) {
52 void window_enter_fullscreen()
54 window.fullscreen = true;
55 GLFWmonitor *monitor = glfwGetPrimaryMonitor();
56 const GLFWvidmode *vidmode = glfwGetVideoMode(monitor);
57 glfwSetWindowMonitor(window.handle, monitor, 0, 0, vidmode->width, vidmode->height, 0);
59 debug_menu_changed(ENTRY_FULLSCREEN);
62 void window_exit_fullscreen()
64 window.fullscreen = false;
65 glfwSetWindowMonitor(window.handle, NULL, small_x, small_y, small_width, small_height, 0);
67 debug_menu_changed(ENTRY_FULLSCREEN);
73 fprintf(stderr, "[error] failed to initialize GLFW\n");
77 glfwWindowHint(GLFW_SAMPLES, client_config.antialiasing);
78 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
79 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
80 glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
84 window.handle = glfwCreateWindow(window.width, window.height, "Dragonblocks", NULL, NULL);
85 window.fullscreen = false;
89 small_width = window.width;
90 small_height = window.height;
93 fprintf(stderr, "[error] failed to create window\n");
98 glfwMakeContextCurrent(window.handle);
100 if (!client_config.vsync)
103 if (glewInit() != GLEW_OK) {
104 fprintf(stderr, "[error] failed to initialize GLEW\n");
108 glfwSetFramebufferSizeCallback(window.handle, &framebuffer_size_callback);
109 glfwSetCursorPosCallback(window.handle, &cursor_pos_callback);
110 glfwSetWindowPosCallback(window.handle, &window_pos_callback);