commit cc905a9753a0742bdcdced04e7ca2b673c3347c2
parent 6d0b1f454360a1c91091f453598e702af56de31d
Author: David DiPaola <DavidDiPaola@users.noreply.github.com>
Date: Wed, 27 Jun 2018 08:05:30 -0400
02, 03: updated 02's shader variables to match 03
Diffstat:
2 files changed, 19 insertions(+), 18 deletions(-)
diff --git a/02-cube.c b/02-cube.c
@@ -19,29 +19,30 @@ int
main() {
GLFWwindow * window = ogl_init(400, 240, "02 - cube");
+ /* vu: vertex uniform, va: vertex attribute, fu: fragment uniform, fv: fragment varying */
const char * program_vertex_source =
"#version 100" "\n"
"precision highp float;" "\n"
- "uniform mat4 uniform_MVP;" "\n" /* uniforms are inputs to vertex shaders that don't change per-vertex */
- "attribute vec3 attribute_position;" "\n" /* attributes are inputs to vertex shaders */
- "attribute vec3 attribute_color;" "\n"
- "varying vec4 varying_color;" "\n" /* varyings are outputs of vertex shaders and inputs to fragment shaders */
+ "uniform mat4 vu_vertex_MVP;" "\n" /* uniforms are inputs to vertex and fragment shaders that don't change per-vertex */
+ "attribute vec3 va_vertex_position;" "\n" /* attributes are inputs to vertex shaders */
+ "attribute vec3 va_vertex_color;" "\n"
+ "varying vec4 fv_vertex_color;" "\n" /* varyings are outputs of vertex shaders and inputs to fragment shaders */
"void main(){" "\n"
- " gl_Position = uniform_MVP * vec4(attribute_position,1);" "\n"
- " varying_color = vec4(attribute_color,1);" "\n"
+ " gl_Position = vu_vertex_MVP * vec4(va_vertex_position,1);" "\n"
+ " fv_vertex_color = vec4(va_vertex_color,1);" "\n"
"}" "\n"
;
const char * program_fragment_source =
"#version 100" "\n"
"precision lowp float;" "\n"
- "varying vec4 varying_color;" "\n"
+ "varying vec4 fv_vertex_color;" "\n"
"void main() {" "\n"
- " gl_FragColor = varying_color;" "\n"
+ " gl_FragColor = fv_vertex_color;" "\n"
"}" "\n"
;
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");
+ GLint program_va_vertex_position_ID = glGetAttribLocation(program_ID, "va_vertex_position");
+ GLint program_va_vertex_color_ID = glGetAttribLocation(program_ID, "va_vertex_color");
struct ogl_mat4f MVP_projection;
ogl_perspective(45.0f, 0.1f, 100.0f, &MVP_projection);
@@ -100,21 +101,21 @@ main() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUseProgram(program_ID);
- ogl_program_uniform_set_mat4f(program_ID, "uniform_MVP", MVP);
+ ogl_program_uniform_set_mat4f(program_ID, "vu_vertex_MVP", MVP);
- glEnableVertexAttribArray(program_attribute_position_ID);
+ glEnableVertexAttribArray(program_va_vertex_position_ID);
glBindBuffer(GL_ARRAY_BUFFER, cube_vertexbuffer_ID);
- glVertexAttribPointer(program_attribute_position_ID, 3, GL_FLOAT, GL_FALSE, 0, (GLvoid *)0);
+ glVertexAttribPointer(program_va_vertex_position_ID, 3, GL_FLOAT, GL_FALSE, 0, (GLvoid *)0);
- glEnableVertexAttribArray(program_attribute_color_ID);
+ glEnableVertexAttribArray(program_va_vertex_color_ID);
glBindBuffer(GL_ARRAY_BUFFER, cube_colorbuffer_ID);
- glVertexAttribPointer(program_attribute_color_ID, 3, GL_FLOAT, GL_FALSE, 0, (GLvoid *)0);
+ glVertexAttribPointer(program_va_vertex_color_ID, 3, GL_FLOAT, GL_FALSE, 0, (GLvoid *)0);
glDrawArrays(GL_TRIANGLES, 0, cube_vertexbuffer_data_vertexes);
glBindBuffer(GL_ARRAY_BUFFER, 0);
- glDisableVertexAttribArray(program_attribute_position_ID);
- glDisableVertexAttribArray(program_attribute_color_ID);
+ glDisableVertexAttribArray(program_va_vertex_position_ID);
+ glDisableVertexAttribArray(program_va_vertex_color_ID);
glfwSwapBuffers(window);
glfwPollEvents();
diff --git a/03-texture.c b/03-texture.c
@@ -184,7 +184,7 @@ main() {
glDeleteBuffers(1, &cube_vertexbuffer_ID);
glDeleteBuffers(1, &cube_texture_UVbuffer_ID);
- //glDeleteBuffers(1, &cube_colorbuffer_ID);
+ glDeleteBuffers(1, &cube_colorbuffer_ID);
glDeleteProgram(program_ID);
//glDeleteTextures(1, &program_uniform_texturesampler_ID);