opengl-learn

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

commit 6455b97b23ccf06f3dd8d4f42fd5e6cf83bda2e9
parent 90b09385b3aba47aa6963c9ff4bc162e0a07b913
Author: David DiPaola <DavidDiPaola@users.noreply.github.com>
Date:   Fri, 22 Jun 2018 18:12:16 -0400

03: alpha in textures should now show "underlying" fragment color

Diffstat:
03-texture.c | 11+++++------
1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/03-texture.c b/03-texture.c @@ -35,9 +35,9 @@ main() { "varying vec4 varying_color;" "\n" /* varyings are outputs of vertex shaders and inputs to fragment shaders */ "varying vec2 varying_UV;" "\n" "void main(){" "\n" - " gl_Position = uniform_MVP * vec4(attribute_position,1);" "\n" + " gl_Position = uniform_MVP * vec4(attribute_position,1);" "\n" " varying_color = vec4(attribute_color,1);" "\n" - " varying_UV = attribute_UV;" "\n" + " varying_UV = attribute_UV;" "\n" "}" "\n" ; const char * program_fragment_source = @@ -47,9 +47,8 @@ main() { "varying vec4 varying_color;" "\n" "varying vec2 varying_UV;" "\n" "void main() {" "\n" - //" gl_FragColor = texture2D(uniform_texturesampler, varying_UV) * varying_color;" "\n" - " gl_FragColor = texture2D(uniform_texturesampler, varying_UV);" "\n" - //" gl_FragColor = varying_color;" "\n" + " vec4 texturesampler_color = texture2D(uniform_texturesampler, varying_UV);" "\n" + " gl_FragColor = mix(texturesampler_color, varying_color, 1.0-texturesampler_color.a);" "\n" "}" "\n" ; GLuint program_ID = ogl_program_build(program_vertex_source, program_fragment_source); @@ -112,7 +111,7 @@ main() { GLuint cube_colorbuffer_ID = ogl_arraybuffer_load(cube_colorbuffer_data, cube_colorbuffer_data_size); uint32_t cube_texture_data[] = { - htobe32(0xFFFF00FF), htobe32(0x0000FFFF), + htobe32(0x00000000), htobe32(0x0000FFFF), htobe32(0xFF0000FF), htobe32(0x00FF00FF), }; const size_t cube_texture_data_width = 2;