#include #include #include "window.hpp" #include #include #define MIN_WIDTH 854 #define MIN_HEIGHT 480 void framebuffer_size_callback(GLFWwindow *window, int width, int height) { glViewport(0, 0, width, height); } GLFWwindow* createWindow(int samples) { GLFWwindow *window; // Initialise GLFW if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW\n"); getchar(); return NULL; } glfwWindowHint(GLFW_SAMPLES, samples); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // To make MacOS happy; should not be needed glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_RESIZABLE, false); //FIXME: Dev-only: Force floating on i3 window = glfwCreateWindow(DEFAULT_WIDTH, DEFAULT_HEIGHT, "Univerxel", NULL, NULL); if (window == NULL) { fprintf(stderr, "Failed to open GLFW window.\n"); getchar(); glfwTerminate(); return NULL; } glfwMakeContextCurrent(window); // Initialize GLEW glewExperimental = true; // Needed for core profile if (glewInit() != GLEW_OK) { fprintf(stderr, "Failed to initialize GLEW\n"); getchar(); glfwTerminate(); return NULL; } // Ensure we can capture the escape key being pressed below glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE); // Hide the mouse and enable unlimited mouvement glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); // Set the mouse at the center of the screen glfwPollEvents(); glfwSetCursorPos(window, DEFAULT_WIDTH / 2, DEFAULT_HEIGHT / 2); // Force aspect ratio glfwSetWindowSizeLimits(window, MIN_WIDTH, MIN_HEIGHT, GLFW_DONT_CARE, GLFW_DONT_CARE); glfwSetWindowAspectRatio(window, RATIO_WIDTH, RATIO_HEIGHT); // Handle resize glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); glfwSetWindowTitle(window, "Univerxel"); glfwSetWindowAttrib(window, GLFW_RESIZABLE, true); // Enable depth test glEnable(GL_DEPTH_TEST); // Accept fragment if it closer to the camera than the former one glDepthFunc(GL_LEQUAL); // Cull triangles which normal is not towards the camera glEnable(GL_CULL_FACE); glCullFace(GL_BACK); GLint smp; glGetIntegerv(GL_SAMPLES, &smp); if(smp > 0) { glEnable(GL_MULTISAMPLE); } return window; }