X-Git-Url: http://git.mutantstargoat.com?a=blobdiff_plain;f=src%2Fopengl%2Fopengl.cc;h=9b220aba8b8a371c5ac4ecfd2f80f2890d3402f6;hb=0c5fa3525b2c8151bf83a215eee992c257d6fa28;hp=46363f43ccd6df651c61641c43d09bfffa406923;hpb=df336012c33f2993bdb80177a1f874ef81e7505f;p=demo diff --git a/src/opengl/opengl.cc b/src/opengl/opengl.cc index 46363f4..9b220ab 100644 --- a/src/opengl/opengl.cc +++ b/src/opengl/opengl.cc @@ -1,12 +1,19 @@ #include +#include #include +#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); +static void zbuffer(bool enable); +static void cull_face(Gfx_cull_face cf); + bool init_opengl() { if(!glfwInit()) { @@ -16,6 +23,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,7 +35,14 @@ bool init_opengl() glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); + glEnable(GL_FRAMEBUFFER_SRGB); // linear colorspace + + gfx_clear = clear; + gfx_viewport = viewport; + gfx_zbuffer = zbuffer; + gfx_cull_face = cull_face; + // glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); return true; } @@ -37,4 +52,40 @@ 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); +} + +static void zbuffer(bool enable) +{ + if(enable) + glEnable(GL_DEPTH_TEST); + else + glDisable(GL_DEPTH_TEST); +} + +static void cull_face(Gfx_cull_face cf) +{ + switch(cf) { + case GFX_CULL_NONE: + glDisable(GL_CULL_FACE); + break; + case GFX_CULL_FRONT: + glEnable(GL_CULL_FACE); + glCullFace(GL_FRONT); + break; + case GFX_CULL_BACK: + glEnable(GL_CULL_FACE); + glCullFace(GL_BACK); + break; + } } \ No newline at end of file