2 #include <GLFW/glfw3.h>
6 #include "opengl/opengl.h"
8 extern GLFWwindow *win;
12 static void clear(float r, float g, float b);
13 static void viewport(int x, int y, int width, int height);
14 static void zbuffer(bool enable);
15 static void cull_face(Gfx_cull_face cf);
16 static void reshape(int width, int height) {}
17 static void wireframe(bool enable);
22 fprintf(stderr, "Failed to initialize GLFW.\n");
26 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
27 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5);
28 glfwWindowHint(GLFW_SRGB_CAPABLE, GLFW_TRUE);
30 if(!(win = glfwCreateWindow(win_w, win_h, "glcow", 0, 0))) {
31 fprintf(stderr, "Failed to create window.\n");
34 glfwMakeContextCurrent(win);
38 glEnable(GL_DEPTH_TEST);
39 glEnable(GL_CULL_FACE);
40 glEnable(GL_FRAMEBUFFER_SRGB); // linear colorspace
43 gfx_viewport = viewport;
44 gfx_zbuffer = zbuffer;
45 gfx_cull_face = cull_face;
46 gfx_reshape = reshape;
47 gfx_wireframe = wireframe;
49 // glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
56 glfwDestroyWindow(win);
61 static void clear(float r, float g, float b)
63 glClearColor(r, g, b, 1.0);
64 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
67 static void viewport(int x, int y, int width, int height)
69 glViewport(x, y, width, height);
72 static void zbuffer(bool enable)
75 glEnable(GL_DEPTH_TEST);
77 glDisable(GL_DEPTH_TEST);
80 static void cull_face(Gfx_cull_face cf)
84 glDisable(GL_CULL_FACE);
87 glEnable(GL_CULL_FACE);
91 glEnable(GL_CULL_FACE);
97 static void wireframe(bool enabled)
100 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
102 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);