]> git.lizzy.rs Git - dragonblocks_alpha.git/blobdiff - src/client/window.c
You can now see other players
[dragonblocks_alpha.git] / src / client / window.c
index 511ee4e4d990be7cac2cbf71e09b8ee089777846..b9460eb14ac3676f4211efe19dcd89fac0fb68a6 100644 (file)
@@ -1,38 +1,51 @@
 #include <stdio.h>
 #include <GL/glew.h>
 #include <GL/gl.h>
+#include "client/client_config.h"
 #include "client/debug_menu.h"
-#include "client/hud.h"
+#include "client/game.h"
+#include "client/gl_debug.h"
+#include "client/gui.h"
 #include "client/input.h"
-#include "client/scene.h"
 #include "client/window.h"
-#include "util.h"
 
 struct Window window;
 
-static void framebuffer_size_callback(unused GLFWwindow *handle, int width, int height)
+static int small_x, small_y, small_width, small_height;
+
+static void update_projection()
+{
+       mat4x4_perspective(window.projection,
+               window.fov / 180.0f * M_PI,
+               (float) window.width / (float) window.height,
+               0.01f, client_config.view_distance + 28.0f);
+}
+
+static void framebuffer_size_callback(__attribute__((unused)) GLFWwindow *handle, int width, int height)
 {
-       glViewport(0, 0, width, height);
+       glViewport(0, 0, width, height); GL_DEBUG
+       window.width = width;
+       window.height = height;
 
-       if (! window.fullscreen) {
-               window.small_bounds.width = width;
-               window.small_bounds.height = height;
+       if (!window.fullscreen) {
+               small_width = width;
+               small_height = height;
        }
 
-       scene_on_resize(width, height);
-       hud_on_resize(width, height);
+       update_projection();
+       gui_update_projection();
 }
 
-static void cursor_pos_callback(unused GLFWwindow *handle, double current_x, double current_y)
+static void cursor_pos_callback(__attribute__((unused)) GLFWwindow *handle, double x, double y)
 {
-       input_on_cursor_pos(current_x, current_y);
+       input_cursor(x, y);
 }
 
-static void window_pos_callback(unused GLFWwindow *handle, int x, int y)
+static void window_pos_callback(__attribute__((unused)) GLFWwindow *handle, int x, int y)
 {
-       if (! window.fullscreen) {
-               window.small_bounds.x = x;
-               window.small_bounds.y = y;
+       if (!window.fullscreen) {
+               small_x = x;
+               small_y = y;
        }
 }
 
@@ -43,44 +56,52 @@ void window_enter_fullscreen()
        const GLFWvidmode *vidmode = glfwGetVideoMode(monitor);
        glfwSetWindowMonitor(window.handle, monitor, 0, 0, vidmode->width, vidmode->height, 0);
 
-       debug_menu_update_fullscreen();
+       debug_menu_changed(ENTRY_FULLSCREEN);
 }
 
 void window_exit_fullscreen()
 {
        window.fullscreen = false;
-       glfwSetWindowMonitor(window.handle, NULL, window.small_bounds.x, window.small_bounds.y, window.small_bounds.width, window.small_bounds.height, 0);
+       glfwSetWindowMonitor(window.handle, NULL, small_x, small_y, small_width, small_height, 0);
 
-       debug_menu_update_fullscreen();
+       debug_menu_changed(ENTRY_FULLSCREEN);
 }
 
-bool window_init(int width, int height)
+bool window_init()
 {
-       if(! glfwInit()) {
-               fprintf(stderr, "Failed to initialize GLFW\n");
+       if(!glfwInit()) {
+               fprintf(stderr, "[error] failed to initialize GLFW\n");
                return false;
        }
 
-       glfwWindowHint(GLFW_SAMPLES, 8);
+       glfwWindowHint(GLFW_SAMPLES, client_config.antialiasing);
        glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
-       glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);
+       glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
        glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
 
-       window.handle = glfwCreateWindow(width, height, "Dragonblocks", NULL, NULL);
+       window.width = 1250;
+       window.height = 750;
+       window.handle = glfwCreateWindow(window.width, window.height, "Dragonblocks", NULL, NULL);
+       window.fullscreen = false;
+       window.fov = 86.1f;
+       update_projection();
 
-       window.small_bounds.width = width;
-       window.small_bounds.height = height;
+       small_width = window.width;
+       small_height = window.height;
 
-       if (! window.handle) {
-               fprintf(stderr, "Failed to create window\n");
+       if (!window.handle) {
+               fprintf(stderr, "[error] failed to create window\n");
                glfwTerminate();
                return false;
        }
 
        glfwMakeContextCurrent(window.handle);
 
+       if (!client_config.vsync)
+               glfwSwapInterval(0);
+
        if (glewInit() != GLEW_OK) {
-               fprintf(stderr, "Failed to initialize GLEW\n");
+               fprintf(stderr, "[error] failed to initialize GLEW\n");
                return false;
        }