Game Development Reference
In-Depth Information
printf("Error: Failed to link GLSL program\n");
int Len = 1024;
char Error[1024];
glGetProgramInfoLog(Program, 1024, &Len, Error);
printf("%s\n", Error);
exit(-1);
}
Optional: Program Validation and Status
You should always validate program objects; it helps to see whether you have syntax
errors in your shader code. To validate a program, use the API call glValidateProgram with
the reference ID of the program. Next, call glGetProgramiv with the program validation
constant GL_VALIDATE_STATUS . The result of the validation is returned in the last argument
( ShaderStatus in this case). Then, simply check the status and handle the error accordingly,
as shown in the following fragment:
glValidateProgram(Program);
glGetProgramiv(Program, GL_VALIDATE_STATUS, &ShaderStatus);
if (ShaderStatus != GL_TRUE) {
printf("Error: Failed to validate GLSL program\n");
exit(-1);
}
Finally, enable and use the program.
Enabling and Using the Program
To start things off, use glUseProgram with the program ID to install a program object as part
of a current rendering state. A program object contains an executable that runs on the vertex
processor if it contains one or more shader objects of type GL_VERTEX_SHADER that have been
successfully compiled and linked.
// Enable the program
glUseProgram (Program);
glEnableVertexAttribArray (0);
glEnableVertexAttribArray (1);
Remember the two local attributes ( Position and Normal ) you declared in the attach step?
They must be enabled before they can take effect. By default, all client-side capabilities
are disabled, including all generic vertex attribute arrays. If enabled, the values in the
generic vertex attribute array will be accessed and used for rendering when calls are made
to vertex array commands such as glDrawArrays , glDrawElements , glDrawRangeElements ,
glArrayElement , glMultiDrawElements , or glMultiDrawArrays .
Now let's put what you have learned so far into practice by building a neat Android project to
draw an icosahedron using shaders.
 
Search WWH ::




Custom Search