5 #include "client/client_config.h"
6 #include "client/debug_menu.h"
7 #include "client/game.h"
8 #include "client/opengl.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 static void error_callback(__attribute__((unused)) int error, const char *description)
61 fprintf(stderr, "[warning] GLFW error: %s\n", description);
64 void window_enter_fullscreen()
66 window.fullscreen = true;
67 GLFWmonitor *monitor = glfwGetPrimaryMonitor();
68 const GLFWvidmode *vidmode = glfwGetVideoMode(monitor);
69 glfwSetWindowMonitor(window.handle, monitor, 0, 0, vidmode->width, vidmode->height, 0);
71 debug_menu_changed(ENTRY_FULLSCREEN);
74 void window_exit_fullscreen()
76 window.fullscreen = false;
77 glfwSetWindowMonitor(window.handle, NULL, small_x, small_y, small_width, small_height, 0);
79 debug_menu_changed(ENTRY_FULLSCREEN);
85 fprintf(stderr, "[error] failed to initialize GLFW\n");
89 glfwSetErrorCallback(&error_callback);
91 glfwWindowHint(GLFW_SAMPLES, client_config.antialiasing);
92 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
93 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
94 glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
98 window.handle = glfwCreateWindow(window.width, window.height, "Dragonblocks", NULL, NULL);
99 window.fullscreen = false;
103 small_width = window.width;
104 small_height = window.height;
106 if (!window.handle) {
107 fprintf(stderr, "[error] failed to create window (does your machine support OpenGL 3.3?)\n");
112 glfwMakeContextCurrent(window.handle);
114 if (!client_config.vsync)
117 if (glewInit() != GLEW_OK) {
118 fprintf(stderr, "[error] failed to initialize GLEW\n");
122 glfwSetFramebufferSizeCallback(window.handle, &framebuffer_size_callback);
123 glfwSetCursorPosCallback(window.handle, &cursor_pos_callback);
124 glfwSetWindowPosCallback(window.handle, &window_pos_callback);
125 glfwSetMouseButtonCallback(window.handle, &mouse_button_callback);