opengl_learn

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

commit bca24bdd13a4c8a1c3db407f836bc8fffbc54c41
parent 9ff0ba052d674aac27924e4fd8c6c4451cb94765
Author: David DiPaola <DavidDiPaola@users.noreply.github.com>
Date:   Sun, 10 Jun 2018 10:55:09 -0400

00,01,02,ogl: made ogl:program:build() exit() on error to simplify caller code

Diffstat:
M00-triangle.c | 7+------
M01-perspective.c | 7+------
M02-cube.c | 7+------
Mogl/ogl.h | 7++-----
Mogl/ogl_program_build.c | 28++++++++--------------------
5 files changed, 13 insertions(+), 43 deletions(-)

diff --git a/00-triangle.c b/00-triangle.c @@ -41,12 +41,7 @@ main() { " gl_FragColor = vec4(1,0,0,1);" "\n" "}" "\n" ; - GLuint program_ID = 0; - status = ogl_program_build(program_vertex_source, program_fragment_source, &program_ID); - if (status < 0) { - fprintf(stderr, "\t" "at %s : %d" "\n", __FILE__, __LINE__); - return status; - } + GLuint program_ID = ogl_program_build(program_vertex_source, program_fragment_source); GLint program_attribute_position_ID = glGetAttribLocation(program_ID, "attribute_position"); const GLfloat triangle_vertexbuffer_data[] = { diff --git a/01-perspective.c b/01-perspective.c @@ -42,12 +42,7 @@ main() { " gl_FragColor = vec4(1,0,0,1);" "\n" "}" "\n" ; - GLuint program_ID = 0; - status = ogl_program_build(program_vertex_source, program_fragment_source, &program_ID); - if (status < 0) { - fprintf(stderr, "\t" "at %s : %d" "\n", __FILE__, __LINE__); - return status; - } + GLuint program_ID = ogl_program_build(program_vertex_source, program_fragment_source); GLint program_attribute_position_ID = glGetAttribLocation(program_ID, "attribute_position"); struct ogl_mat4f MVP_projection; diff --git a/02-cube.c b/02-cube.c @@ -46,12 +46,7 @@ main() { " gl_FragColor = varying_color;" "\n" "}" "\n" ; - GLuint program_ID = 0; - status = ogl_program_build(program_vertex_source, program_fragment_source, &program_ID); - if (status < 0) { - fprintf(stderr, "\t" "at %s : %d" "\n", __FILE__, __LINE__); - return status; - } + GLuint program_ID = ogl_program_build(program_vertex_source, program_fragment_source); GLint program_attribute_position_ID = glGetAttribLocation(program_ID, "attribute_position"); GLint program_attribute_color_ID = glGetAttribLocation(program_ID, "attribute_color"); diff --git a/ogl/ogl.h b/ogl/ogl.h @@ -42,11 +42,8 @@ ogl_perspective( struct ogl_mat4f * out_matrix ); -int -ogl_program_build( - const char * vertexshader, const char * fragmentshader, - GLuint * out_program_ID -); +GLuint +ogl_program_build(const char * program_vertex_source, const char * program_fragment_source); int ogl_program_uniform_get_ID( diff --git a/ogl/ogl_program_build.c b/ogl/ogl_program_build.c @@ -45,33 +45,22 @@ _shader_compile( return 0; } -int -ogl_program_build( - const char * vertexshader, const char * fragmentshader, - GLuint * out_program_ID -) { - /* - GLenum status; - status = glGetError(); - if (status != GL_NO_ERROR) { - fprintf(stderr, "GL ERROR: foo() failed (GLenum %i)" "\n", status); - fprintf(stderr, "\t" "at %s : %d" "\n", __FILE__, __LINE__); - } - */ +GLuint +ogl_program_build(const char * program_vertex_source, const char * program_fragment_source) { int status; GLuint vertexshader_ID; - status = _shader_compile(GL_VERTEX_SHADER, vertexshader, &vertexshader_ID); + status = _shader_compile(GL_VERTEX_SHADER, program_vertex_source, &vertexshader_ID); if (status < 0) { fprintf(stderr, "\t" "at %s : %d" "\n", __FILE__, __LINE__); - return -1; + exit(-1); } GLuint fragmentshader_ID; - status = _shader_compile(GL_FRAGMENT_SHADER, fragmentshader, &fragmentshader_ID); + status = _shader_compile(GL_FRAGMENT_SHADER, program_fragment_source, &fragmentshader_ID); if (status < 0) { fprintf(stderr, "\t" "at %s : %d" "\n", __FILE__, __LINE__); - return -1; + exit(-1); } GLuint program_ID = glCreateProgram(); @@ -91,7 +80,7 @@ ogl_program_build( if (status_compile != GL_TRUE) { fprintf(stderr, "GL shader program linker: ERROR" "\n"); fprintf(stderr, "\t" "at %s : %d" "\n", __FILE__, __LINE__); - return -1; + exit(-1); } glDetachShader(program_ID, vertexshader_ID); @@ -100,7 +89,6 @@ ogl_program_build( glDeleteShader(vertexshader_ID); glDeleteShader(fragmentshader_ID); - (*out_program_ID) = program_ID; - return 0; + return program_ID; }