X-Git-Url: http://git.mutantstargoat.com?a=blobdiff_plain;f=src%2Fopengl%2Fopengl.cc;h=66dd002e5a4c2c04c3bb4730ccf654b1d40dfeb7;hb=72995482b98ff2a014ddd737131a0935ead89977;hp=d2aea3b27b3574b74c43c08ebb8bccdacc6af06b;hpb=826b0cf7adaf8b1dc4c37f57a4a98c79a3995e21;p=demo diff --git a/src/opengl/opengl.cc b/src/opengl/opengl.cc index d2aea3b..66dd002 100644 --- a/src/opengl/opengl.cc +++ b/src/opengl/opengl.cc @@ -1,15 +1,20 @@ #include +#include #include +#include "gfxapi.h" #include "opengl/opengl.h" extern GLFWwindow *win; extern int win_h; extern int win_w; -/* static test_* functions are going to be removed: just to test the shaders */ -static void test_draw(); -static void test_torus(); +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); +static void reshape(int width, int height) {} +static void wireframe(bool enable); bool init_opengl() { @@ -20,6 +25,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"); @@ -28,6 +34,19 @@ bool init_opengl() glfwMakeContextCurrent(win); glewInit(); + + 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; + gfx_reshape = reshape; + gfx_wireframe = wireframe; + + // glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); return true; } @@ -39,15 +58,46 @@ void cleanup_opengl() glfwTerminate(); } -void display_opengl() +static void clear(float r, float g, float b) { + glClearColor(r, g, b, 1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glClearColor(0.5, 0.5, 0.5, 1.0); +} + +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 test_draw() +static void cull_face(Gfx_cull_face cf) { - /* this function is going to be removed, it's here only to test the shaders */ + 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 +static void wireframe(bool enabled) +{ + if(enabled) + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + else + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); +}