opengl-learn

step-by-step introduction to OpenGL
git clone https://0xdd.org/code/opengl-learn.git
Log | Files | Refs | README | LICENSE

commit 775644701cd394b129ac2605f9ae2a229f4207e4
parent 063455c0f7756d7d93d0da588962c536c6bf2161
Author: David DiPaola <DavidDiPaola@users.noreply.github.com>
Date:   Sat,  6 Oct 2018 14:44:09 -0400

ogl: added parameter to init() to enable/disable v-sync

Diffstat:
00-triangle.c | 2+-
01-perspective.c | 2+-
02-cube.c | 2+-
03-texture.c | 2+-
04-lighting.c | 2+-
05-geometrytransforms.c | 2+-
ogl/ogl.h | 2+-
ogl/ogl_init.c | 6+++++-
8 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/00-triangle.c b/00-triangle.c @@ -17,7 +17,7 @@ licensed under CC0 (public domain, see https://creativecommons.org/publicdomain/ int main() { - GLFWwindow * window = ogl_init(400, 240, "00 - triangle"); + GLFWwindow * window = ogl_init(400, 240, 1, "00 - triangle"); /* vu: vertex shader uniform, va: vertex shader attribute, fu: fragment shader uniform, fv: fragment shader varying */ const char * program_vertex_source = diff --git a/01-perspective.c b/01-perspective.c @@ -17,7 +17,7 @@ licensed under CC0 (public domain, see https://creativecommons.org/publicdomain/ int main() { - GLFWwindow * window = ogl_init(400, 240, "01 - triangle with perspective"); + GLFWwindow * window = ogl_init(400, 240, 1, "01 - triangle with perspective"); /* vu: vertex shader uniform, va: vertex shader attribute, fu: fragment shader uniform, fv: fragment shader varying */ const char * program_vertex_source = diff --git a/02-cube.c b/02-cube.c @@ -17,7 +17,7 @@ licensed under CC0 (public domain, see https://creativecommons.org/publicdomain/ int main() { - GLFWwindow * window = ogl_init(400, 240, "02 - cube"); + GLFWwindow * window = ogl_init(400, 240, 1, "02 - cube"); /* vu: vertex shader uniform, va: vertex shader attribute, fu: fragment shader uniform, fv: fragment shader varying */ const char * program_vertex_source = diff --git a/03-texture.c b/03-texture.c @@ -23,7 +23,7 @@ licensed under CC0 (public domain, see https://creativecommons.org/publicdomain/ int main() { - GLFWwindow * window = ogl_init(400, 240, "03 - texture"); + GLFWwindow * window = ogl_init(400, 240, 1, "03 - texture"); /* vu: vertex shader uniform, va: vertex shader attribute, fu: fragment shader uniform, fv: fragment shader varying */ const char * program_vertex_source = diff --git a/04-lighting.c b/04-lighting.c @@ -23,7 +23,7 @@ licensed under CC0 (public domain, see https://creativecommons.org/publicdomain/ int main() { - GLFWwindow * window = ogl_init(400, 240, "04 - lighting"); + GLFWwindow * window = ogl_init(400, 240, 1, "04 - lighting"); /* vu: vertex shader uniform, va: vertex shader attribute, fu: fragment shader uniform, fv: fragment shader varying */ const char * program_vertex_source = diff --git a/05-geometrytransforms.c b/05-geometrytransforms.c @@ -23,7 +23,7 @@ licensed under CC0 (public domain, see https://creativecommons.org/publicdomain/ int main() { - GLFWwindow * window = ogl_init(400, 240, "05 - geometry transforms"); + GLFWwindow * window = ogl_init(400, 240, 1, "05 - geometry transforms"); /* vu: vertex shader uniform, va: vertex shader attribute, fu: fragment shader uniform, fv: fragment shader varying */ const char * program_vertex_source = diff --git a/ogl/ogl.h b/ogl/ogl.h @@ -30,7 +30,7 @@ struct ogl_quat { GLFWwindow * -ogl_init(int window_width, int window_height, const char * window_title); +ogl_init(int window_width, int window_height, int vsync, const char * window_title); diff --git a/ogl/ogl_init.c b/ogl/ogl_init.c @@ -15,7 +15,7 @@ licensed under CC0 (public domain, see https://creativecommons.org/publicdomain/ #include "_ogl.h" GLFWwindow * -ogl_init(int window_width, int window_height, const char * window_title) { +ogl_init(int window_width, int window_height, int vsync, const char * window_title) { GLFWwindow * window; int status; @@ -53,6 +53,10 @@ ogl_init(int window_width, int window_height, const char * window_title) { glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE); + if (!vsync) { + glfwSwapInterval(0); + } + glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glEnable(GL_DEPTH_TEST);