graphics api abstraction
[demo] / src / opengl / opengl.cc
index 46363f4..ffa1d47 100644 (file)
@@ -1,12 +1,16 @@
 #include <GL/glew.h>
 #include <stdio.h>
 
+#include "gfxapi.h"
 #include "opengl/opengl.h"
 
 extern GLFWwindow *win;
 extern int win_h;
 extern int win_w;
 
+static void clear(float r, float g, float b);
+static void viewport(int x, int y, int width, int height);
+
 bool init_opengl()
 {
        if(!glfwInit()) {
@@ -16,6 +20,7 @@ bool init_opengl()
 
        glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
        glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5);
+       glfwWindowHint(GLFW_SRGB_CAPABLE, GLFW_TRUE);
 
        if(!(win = glfwCreateWindow(win_w, win_h, "glcow", 0, 0))) {
                fprintf(stderr, "Failed to create window.\n");
@@ -27,6 +32,10 @@ bool init_opengl()
 
        glEnable(GL_DEPTH_TEST);
        glEnable(GL_CULL_FACE);
+       glEnable(GL_FRAMEBUFFER_SRGB); // linear colorspace
+
+       gfx_clear = clear;
+       gfx_viewport = viewport;
 
        return true;
 }
@@ -37,4 +46,15 @@ void cleanup_opengl()
                glfwDestroyWindow(win);
        }
        glfwTerminate();
+}
+
+static void clear(float r, float g, float b)
+{
+       glClearColor(r, g, b, 1.0);
+       glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+}
+
+static void viewport(int x, int y, int width, int height)
+{
+       glViewport(x, y, width, height);
 }
\ No newline at end of file