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 static void mouse_button_callback(__attribute__((unused)) GLFWwindow *handle, int button, int action, __attribute__((unused)) int mods)
54 if ((button == GLFW_MOUSE_BUTTON_RIGHT || button == GLFW_MOUSE_BUTTON_LEFT) && action == GLFW_PRESS)
55 input_click(button == GLFW_MOUSE_BUTTON_LEFT);
58 void window_enter_fullscreen()
60 window.fullscreen = true;
61 GLFWmonitor *monitor = glfwGetPrimaryMonitor();
62 const GLFWvidmode *vidmode = glfwGetVideoMode(monitor);
63 glfwSetWindowMonitor(window.handle, monitor, 0, 0, vidmode->width, vidmode->height, 0);
65 debug_menu_changed(ENTRY_FULLSCREEN);
68 void window_exit_fullscreen()
70 window.fullscreen = false;
71 glfwSetWindowMonitor(window.handle, NULL, small_x, small_y, small_width, small_height, 0);
73 debug_menu_changed(ENTRY_FULLSCREEN);
79 fprintf(stderr, "[error] failed to initialize GLFW\n");
83 glfwWindowHint(GLFW_SAMPLES, client_config.antialiasing);
84 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
85 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
86 glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
90 window.handle = glfwCreateWindow(window.width, window.height, "Dragonblocks", NULL, NULL);
91 window.fullscreen = false;
95 small_width = window.width;
96 small_height = window.height;
99 fprintf(stderr, "[error] failed to create window\n");
104 glfwMakeContextCurrent(window.handle);
106 if (!client_config.vsync)
109 if (glewInit() != GLEW_OK) {
110 fprintf(stderr, "[error] failed to initialize GLEW\n");
114 glfwSetFramebufferSizeCallback(window.handle, &framebuffer_size_callback);
115 glfwSetCursorPosCallback(window.handle, &cursor_pos_callback);
116 glfwSetWindowPosCallback(window.handle, &window_pos_callback);
117 glfwSetMouseButtonCallback(window.handle, &mouse_button_callback);