opengl_learn

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

commit 070a197bf5ffbcdb33ef200696b0b7524d005fa3
parent bca24bdd13a4c8a1c3db407f836bc8fffbc54c41
Author: David DiPaola <DavidDiPaola@users.noreply.github.com>
Date:   Sun, 10 Jun 2018 11:04:36 -0400

ogl: renamed vertex:buffer:load() to arraybuffer:load()

Diffstat:
M00-triangle.c | 2+-
M01-perspective.c | 2+-
M02-cube.c | 4++--
Mogl/Makefile | 5++---
Mogl/ogl.h | 36++++++++++++++++++++++++------------
Aogl/ogl_arraybuffer_load.c | 22++++++++++++++++++++++
Dogl/ogl_vertex_buffer_load.c | 22----------------------
7 files changed, 52 insertions(+), 41 deletions(-)

diff --git a/00-triangle.c b/00-triangle.c @@ -50,7 +50,7 @@ main() { const size_t triangle_vertexbuffer_data_size = sizeof(triangle_vertexbuffer_data); const size_t triangle_vertexbuffer_data_vertexes = (sizeof(triangle_vertexbuffer_data) / sizeof(*triangle_vertexbuffer_data)) / 3; GLuint triangle_vertexbuffer_ID = 0; - status = ogl_vertex_buffer_load(triangle_vertexbuffer_data, triangle_vertexbuffer_data_size, &triangle_vertexbuffer_ID); + status = ogl_arraybuffer_load(triangle_vertexbuffer_data, triangle_vertexbuffer_data_size, &triangle_vertexbuffer_ID); if (status < 0) { return status; } diff --git a/01-perspective.c b/01-perspective.c @@ -73,7 +73,7 @@ main() { const size_t triangle_vertexbuffer_data_size = sizeof(triangle_vertexbuffer_data); const size_t triangle_vertexbuffer_data_vertexes = (sizeof(triangle_vertexbuffer_data) / sizeof(*triangle_vertexbuffer_data)) / 3; GLuint triangle_vertexbuffer_ID = 0; - status = ogl_vertex_buffer_load(triangle_vertexbuffer_data, triangle_vertexbuffer_data_size, &triangle_vertexbuffer_ID); + status = ogl_arraybuffer_load(triangle_vertexbuffer_data, triangle_vertexbuffer_data_size, &triangle_vertexbuffer_ID); if (status < 0) { return status; } diff --git a/02-cube.c b/02-cube.c @@ -89,7 +89,7 @@ main() { static const size_t cube_vertexbuffer_data_size = sizeof(cube_vertexbuffer_data); static const size_t cube_vertexbuffer_data_vertexes = (sizeof(cube_vertexbuffer_data) / sizeof(*cube_vertexbuffer_data)) / 3; GLuint cube_vertexbuffer_ID = 0; - status = ogl_vertex_buffer_load(cube_vertexbuffer_data, cube_vertexbuffer_data_size, &cube_vertexbuffer_ID); + status = ogl_arraybuffer_load(cube_vertexbuffer_data, cube_vertexbuffer_data_size, &cube_vertexbuffer_ID); if (status < 0) { return status; } @@ -110,7 +110,7 @@ main() { }; static const size_t cube_colorbuffer_data_size = sizeof(cube_colorbuffer_data); GLuint cube_colorbuffer_ID = 0; - status = ogl_vertex_buffer_load(cube_colorbuffer_data, cube_colorbuffer_data_size, &cube_colorbuffer_ID); + status = ogl_arraybuffer_load(cube_colorbuffer_data, cube_colorbuffer_data_size, &cube_colorbuffer_ID); if (status < 0) { return status; } diff --git a/ogl/Makefile b/ogl/Makefile @@ -2,11 +2,10 @@ SRC = \ _ogl.c ogl_init.c \ ogl_GLfloat_isapproxequal.c ogl_GLfloat_print.c \ ogl_mat4f_identity.c ogl_mat4f_isapproxequal.c ogl_mat4f_multiply.c ogl_mat4f_print.c \ - ogl_lookat.c \ - ogl_perspective.c \ ogl_program_build.c ogl_program_uniform_get_ID.c ogl_program_uniform_set_mat4f.c \ ogl_vec3f_cross.c ogl_vec3f_dot.c ogl_vec3f_isapproxequal.c ogl_vec3f_magnitude.c ogl_vec3f_normal.c ogl_vec3f_print.c \ - ogl_vertex_buffer_load.c + ogl_arraybuffer_load.c \ + ogl_lookat.c ogl_perspective.c OBJ = $(SRC:.c=.o) BIN = ogl.a TEST = \ diff --git a/ogl/ogl.h b/ogl/ogl.h @@ -30,17 +30,10 @@ ogl_init( GLFWwindow ** out_window ); -void -ogl_lookat( - struct ogl_vec3f eye, struct ogl_vec3f center, struct ogl_vec3f up, - struct ogl_mat4f * out_matrix -); -int -ogl_perspective( - GLfloat fovy, GLfloat zNear, GLfloat zFar, - struct ogl_mat4f * out_matrix -); + + + GLuint ogl_program_build(const char * program_vertex_source, const char * program_fragment_source); @@ -56,15 +49,16 @@ ogl_program_uniform_set_mat4f( GLint program_ID, const char * uniform_name, const struct ogl_mat4f matrix ); + + int -ogl_vertex_buffer_load( +ogl_arraybuffer_load( const GLvoid * data, GLsizeiptr data_size, GLuint * out_bufferID ); - int ogl_GLfloat_isapproxequal( GLfloat a, GLfloat b @@ -75,6 +69,8 @@ ogl_GLfloat_print( GLfloat f ); + + void ogl_mat4f_identity( struct ogl_mat4f * out_matrix @@ -96,6 +92,8 @@ ogl_mat4f_print( struct ogl_mat4f matrix, const char * line_prefix, const char * line_suffix ); + + void ogl_vec3f_cross( struct ogl_vec3f a, struct ogl_vec3f b, @@ -129,5 +127,19 @@ ogl_vec3f_print( struct ogl_vec3f vector ); + + +void +ogl_lookat( + struct ogl_vec3f eye, struct ogl_vec3f center, struct ogl_vec3f up, + struct ogl_mat4f * out_matrix +); + +int +ogl_perspective( + GLfloat fovy, GLfloat zNear, GLfloat zFar, + struct ogl_mat4f * out_matrix +); + #endif diff --git a/ogl/ogl_arraybuffer_load.c b/ogl/ogl_arraybuffer_load.c @@ -0,0 +1,22 @@ +/* +2018 David DiPaola +licensed under CC0 (public domain, see https://creativecommons.org/publicdomain/zero/1.0/) +*/ + +#include <GL/glew.h> + +int +ogl_arraybuffer_load( + const GLvoid * data, GLsizeiptr data_size, + GLuint * out_buffer_ID +) { + GLuint buffer_ID; + glGenBuffers(1, &buffer_ID); + glBindBuffer(GL_ARRAY_BUFFER, buffer_ID); + glBufferData(GL_ARRAY_BUFFER, data_size, data, GL_STATIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, 0); + + (*out_buffer_ID) = buffer_ID; + return 0; +} + diff --git a/ogl/ogl_vertex_buffer_load.c b/ogl/ogl_vertex_buffer_load.c @@ -1,22 +0,0 @@ -/* -2018 David DiPaola -licensed under CC0 (public domain, see https://creativecommons.org/publicdomain/zero/1.0/) -*/ - -#include <GL/glew.h> - -int -ogl_vertex_buffer_load( - const GLvoid * data, GLsizeiptr data_size, - GLuint * out_buffer_ID -) { - GLuint buffer_ID; - glGenBuffers(1, &buffer_ID); - glBindBuffer(GL_ARRAY_BUFFER, buffer_ID); - glBufferData(GL_ARRAY_BUFFER, data_size, data, GL_STATIC_DRAW); - glBindBuffer(GL_ARRAY_BUFFER, 0); - - (*out_buffer_ID) = buffer_ID; - return 0; -} -