5 #include "client/client_config.h"
6 #include "client/debug_menu.h"
7 #include "client/game.h"
8 #include "client/gl_debug.h"
9 #include "client/gui.h"
10 #include "client/input.h"
11 #include "client/window.h"
15 static int small_x, small_y, small_width, small_height;
17 static void update_projection()
19 mat4x4_perspective(window.projection,
20 window.fov / 180.0f * M_PI,
21 (float) window.width / (float) window.height,
22 0.01f, client_config.view_distance + 28.0f);
25 static void framebuffer_size_callback(__attribute__((unused)) GLFWwindow *handle, int width, int height)
27 glViewport(0, 0, width, height); GL_DEBUG
29 window.height = height;
31 if (!window.fullscreen) {
33 small_height = height;
37 gui_update_projection();
40 static void cursor_pos_callback(__attribute__((unused)) GLFWwindow *handle, double x, double y)
45 static void window_pos_callback(__attribute__((unused)) GLFWwindow *handle, int x, int y)
47 if (!window.fullscreen) {
53 static void mouse_button_callback(__attribute__((unused)) GLFWwindow *handle, int button, int action, __attribute__((unused)) int mods)
55 if ((button == GLFW_MOUSE_BUTTON_RIGHT || button == GLFW_MOUSE_BUTTON_LEFT) && action == GLFW_PRESS)
56 input_click(button == GLFW_MOUSE_BUTTON_LEFT);
59 void window_enter_fullscreen()
61 window.fullscreen = true;
62 GLFWmonitor *monitor = glfwGetPrimaryMonitor();
63 const GLFWvidmode *vidmode = glfwGetVideoMode(monitor);
64 glfwSetWindowMonitor(window.handle, monitor, 0, 0, vidmode->width, vidmode->height, 0);
66 debug_menu_changed(ENTRY_FULLSCREEN);
69 void window_exit_fullscreen()
71 window.fullscreen = false;
72 glfwSetWindowMonitor(window.handle, NULL, small_x, small_y, small_width, small_height, 0);
74 debug_menu_changed(ENTRY_FULLSCREEN);
80 fprintf(stderr, "[error] failed to initialize GLFW\n");
84 glfwWindowHint(GLFW_SAMPLES, client_config.antialiasing);
85 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
86 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
87 glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
91 window.handle = glfwCreateWindow(window.width, window.height, "Dragonblocks", NULL, NULL);
92 window.fullscreen = false;
96 small_width = window.width;
97 small_height = window.height;
100 fprintf(stderr, "[error] failed to create window\n");
105 glfwMakeContextCurrent(window.handle);
107 if (!client_config.vsync)
110 if (glewInit() != GLEW_OK) {
111 fprintf(stderr, "[error] failed to initialize GLEW\n");
115 glfwSetFramebufferSizeCallback(window.handle, &framebuffer_size_callback);
116 glfwSetCursorPosCallback(window.handle, &cursor_pos_callback);
117 glfwSetWindowPosCallback(window.handle, &window_pos_callback);
118 glfwSetMouseButtonCallback(window.handle, &mouse_button_callback);