opengl_learn

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

commit ebec8290bd023f5cac868dbd5f0325e5b763d9de
parent 109a302eeb2c5173976521e1b7e3089df0b35be7
Author: David DiPaola <DavidDiPaola@users.noreply.github.com>
Date:   Sun, 10 Jun 2018 11:36:54 -0400

ogl: init() now exits on error to make caller code simpler

Diffstat:
M00-triangle.c | 9+--------
M01-perspective.c | 7+------
M02-cube.c | 7+------
Mogl/ogl.h | 10++--------
Mogl/ogl_init.c | 18++++++++----------
5 files changed, 13 insertions(+), 38 deletions(-)

diff --git a/00-triangle.c b/00-triangle.c @@ -17,14 +17,7 @@ licensed under CC0 (public domain, see https://creativecommons.org/publicdomain/ int main() { - int status; - - GLFWwindow * window = NULL; - status = ogl_init(400, 240, "00 - triangle", &window); - if (status < 0) { - fprintf(stderr, "\t" "at %s : %d" "\n", __FILE__, __LINE__); - return status; - } + GLFWwindow * window = ogl_init(400, 240, "00 - triangle"); const char * program_vertex_source = "#version 100" "\n" diff --git a/01-perspective.c b/01-perspective.c @@ -19,12 +19,7 @@ int main() { int status; - GLFWwindow * window = NULL; - status = ogl_init(400, 240, "01 - triangle with perspective", &window); - if (status < 0) { - fprintf(stderr, "\t" "at %s : %d" "\n", __FILE__, __LINE__); - return status; - } + GLFWwindow * window = ogl_init(400, 240, "01 - triangle with perspective"); const char * program_vertex_source = "#version 100" "\n" diff --git a/02-cube.c b/02-cube.c @@ -19,12 +19,7 @@ int main() { int status; - GLFWwindow * window = NULL; - status = ogl_init(400, 240, "02 - cube", &window); - if (status < 0) { - fprintf(stderr, "\t" "at %s : %d" "\n", __FILE__, __LINE__); - return status; - } + GLFWwindow * window = ogl_init(400, 240, "02 - cube"); const char * program_vertex_source = "#version 100" "\n" diff --git a/ogl/ogl.h b/ogl/ogl.h @@ -24,14 +24,8 @@ struct ogl_vec3f { -int -ogl_init( - int window_width, int window_height, const char * window_title, - GLFWwindow ** out_window -); - - - +GLFWwindow * +ogl_init(int window_width, int window_height, const char * window_title); diff --git a/ogl/ogl_init.c b/ogl/ogl_init.c @@ -5,6 +5,8 @@ licensed under CC0 (public domain, see https://creativecommons.org/publicdomain/ #include <stdio.h> +#include <stdlib.h> + #include <GL/glew.h> #include <GLFW/glfw3.h> @@ -12,11 +14,8 @@ licensed under CC0 (public domain, see https://creativecommons.org/publicdomain/ #include "ogl.h" #include "_ogl.h" -int -ogl_init( - int window_width, int window_height, const char * window_title, - GLFWwindow ** out_window -) { +GLFWwindow * +ogl_init(int window_width, int window_height, const char * window_title) { GLFWwindow * window; int status; @@ -26,7 +25,7 @@ ogl_init( if (!status) { /* TODO GLFW_TRUE doesn't exist..? */ fprintf(stderr, "GLFW glfwInit(): ERROR" "\n"); fprintf(stderr, "\t" "at %s : %d" "\n", __FILE__, __LINE__); - return -1; + exit(-1); } glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API); @@ -38,7 +37,7 @@ ogl_init( fprintf(stderr, "GLFW glfwCreateWindow(): ERROR" "\n"); fprintf(stderr, "\t" "at %s : %d" "\n", __FILE__, __LINE__); glfwTerminate(); - return -1; + exit(-1); } glfwMakeContextCurrent(window); @@ -49,7 +48,7 @@ ogl_init( fprintf(stderr, "GLEW glewInit(): ERROR" "\n"); fprintf(stderr, "\t" "at %s : %d" "\n", __FILE__, __LINE__); glfwTerminate(); - return -1; + exit(-1); } glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE); @@ -59,9 +58,8 @@ ogl_init( glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); - (*out_window) = window; _ogl_window_width = window_width; _ogl_window_height = window_height; - return 0; + return window; }