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);
18 static void swapbuffers();
19 static void begin_drawing();
20 static void end_drawing();
25 fprintf(stderr, "Failed to initialize GLFW.\n");
29 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
30 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5);
31 glfwWindowHint(GLFW_SRGB_CAPABLE, GLFW_TRUE);
33 if(!(win = glfwCreateWindow(win_w, win_h, "glcow", 0, 0))) {
34 fprintf(stderr, "Failed to create window.\n");
37 glfwMakeContextCurrent(win);
41 glEnable(GL_DEPTH_TEST);
42 glEnable(GL_CULL_FACE);
43 glEnable(GL_FRAMEBUFFER_SRGB); // linear colorspace
46 gfx_viewport = viewport;
47 gfx_zbuffer = zbuffer;
48 gfx_cull_face = cull_face;
49 gfx_reshape = reshape;
50 gfx_wireframe = wireframe;
51 gfx_swapbuffers = swapbuffers;
52 gfx_begin_drawing = begin_drawing;
53 gfx_end_drawing = end_drawing;
55 // glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
62 glfwDestroyWindow(win);
67 static void clear(float r, float g, float b)
69 glClearColor(r, g, b, 1.0);
70 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
73 static void viewport(int x, int y, int width, int height)
75 glViewport(x, y, width, height);
78 static void zbuffer(bool enable)
81 glEnable(GL_DEPTH_TEST);
83 glDisable(GL_DEPTH_TEST);
86 static void cull_face(Gfx_cull_face cf)
90 glDisable(GL_CULL_FACE);
93 glEnable(GL_CULL_FACE);
97 glEnable(GL_CULL_FACE);
103 static void wireframe(bool enabled)
106 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
108 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
111 static void swapbuffers()
113 glfwSwapBuffers(win);
116 static void begin_drawing()
120 static void end_drawing()