WebGL Textures & Vertices

Beginner's Guide

Page Forty

Shader Source Code

This book uses default shaders declared within GLControl.js. For vertex shaders, method getShader() assigns the following String to the local variable sCode.

sCode = "attribute vec4 a_position;"   
+"attribute vec2 a_tex_coord0;"
+"varying vec2 v_tex_coord0;"
           
+"uniform mat4 um4_matrix;"
+"uniform mat4 um4_pmatrix;" 
           
+"void main(void) {"
+ "gl_Position = um4_pmatrix * um4_matrix * a_position;" 
+ "v_tex_coord0 = a_tex_coord0;"      
+"}";

Listing 36: Assign the Default Vertex Shader

For fragment shaders, method getShader() assigns the following String to the local variable sCode.

sCode = "precision mediump float;"
+"uniform sampler2D u_sampler0;"
+"varying vec2 v_tex_coord0;"
        
+" void main(void) {"
+"gl_FragColor = texture2D(u_sampler0, v_tex_coord0);"
+"}";

Listing 37: Assign the Default Fragment Shader

WebGL Beginner's Guide Introduction WebGL Beginner's Guide
Copyright © 2015 Seven Thunder Software. All Rights Reserved.