window.c (1279B)
1 #include "minecraft.h" 2 3 GLFWwindow *Window; 4 5 static float last_x = WINDOW_WIDTH / 2.0f; 6 static float last_y = WINDOW_HEIGHT / 2.0f; 7 static int first_mouse = 1; 8 9 void framebuffer_size_callback(GLFWwindow* window, 10 int width, int height) { 11 (void)window; 12 glViewport(0, 0, width, height); 13 } 14 15 static void mouse_callback(GLFWwindow* window, double xpos, double ypos) { 16 (void)window; 17 18 if (first_mouse) { 19 last_x = (float)xpos; 20 last_y = (float)ypos; 21 first_mouse = 0; 22 } 23 24 float dx = (float)xpos - last_x; 25 float dy = last_y - (float)ypos; 26 27 last_x = (float)xpos; 28 last_y = (float)ypos; 29 30 camera_process_mouse(dx, dy); 31 } 32 33 void window_init() { 34 glfwInit(); 35 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); 36 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); 37 glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); 38 39 Window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, 40 WINDOW_TITLE, NULL, NULL); 41 42 glfwMakeContextCurrent(Window); 43 glfwSwapInterval(1); 44 45 glfwSetFramebufferSizeCallback(Window, framebuffer_size_callback); 46 glfwSetCursorPosCallback(Window, mouse_callback); 47 glfwSetInputMode(Window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); 48 49 glEnable(GL_DEPTH_TEST); 50 glEnable(GL_CULL_FACE); 51 glCullFace(GL_BACK); 52 glFrontFace(GL_CCW); 53 }