Game Development Reference
In-Depth Information
void main(void)
{
lowp vec3 Color = vec3(1.0, 0.0, 0.0);
mediump vec3 Norm = normalize(NormVec);
mediump vec3 Light = normalize(LighVec);
mediump float Diffuse = dot(Norm, Light);
gl_FragColor = vec4(Color * (max(Diffuse, 0.0) * 0.6 + 0.4), 1.0);
}
Scene Initialization
The scene initialization in Listing 4-11 performs the following steps:
1.
It creates two shader programs, vertex, and fragment.
Shader[0] = glCreateShader(GL_VERTEX_SHADER);
Shader[1] = glCreateShader(GL_FRAGMENT_SHADER);
2.
It loads the vertex shader.
LoadShader((char *)VertexShader, Shader[0]);
3.
It loads the fragment shader. Note that VertexShader and
FragmentShaderRed are two strings describing the shaders in
Listing 3-28 from Chapter 3.
LoadShader((char *)FragmentShaderRed, Shader[1]);
4.
It creates the program and attaches the shaders and attributes.
Program = glCreateProgram();
glAttachShader(Program, Shader[0]);
glAttachShader(Program, Shader[1]);
5.
It attaches the attributes or variables ( Position and Normal ) used by
the master and shader programs to manipulate the vertex and face
information of the icosahedron.
glBindAttribLocation(Program, 0, "Position");
glBindAttribLocation(Program, 1, "Normal");
6.
It links the program using its program ID, glLinkProgram(Program) .
7.
It validates the program status by querying the status using the
GL_VALIDATE_STATUS constant.
glValidateProgram(Program);
glGetProgramiv(Program, GL_VALIDATE_STATUS, &ShaderStatus);
if (ShaderStatus != GL_TRUE) {
// handle error
}
 
Search WWH ::




Custom Search