Graphics Reference
In-Depth Information
As an idea of how this is done, consider the code fragment
GLchar *ArrayOfStrings[3];
ArrayOfStrings[0] = “#define SMOOTH_SHADING”;
ArrayofStrings[1] = “ . . . some commonly-used procedure
. . . ”;
ArrayofStrings[2] = “ . . . the real vertex shader code
. . . ”;
glShaderSource( vertShader, 3, (GLchar **)ArrayofStrings,
NULL );
This includes a #define statement, a common function, and the basic
shader source.
If you want to prepare your shader source in a single file and still use this
approach, you can either read the source into a string in a one-dimensional
array, as
GLchar *buffer[1];
buffer[0] = “ . . . the entire shader code . . . ”;
glShaderSource( vertShader, 1, (GLchar **)buffer, NULL );
Or you can read the shader source into a single buffer, but cast its address
as
GLchar *buffer = “ . . . the entire shader code . . . ”;
glShaderSource( vertShader, 1, (const GLchar **)&buffer,
NULL );
The CheckGLErrors Function
The CheckGlErrors function is critical, because OpenGL does not report errors,
so you need to ask. The CheckGlErrors function is shown below. It is an excel-
lent idea to include this in all your OpenGL programs, not just shader pro-
grams, and to call it frequently. Simply knowing that errors occurred (as you
would find when you checked GL_COMPILE_STATUS ) is not enough; you need
to get the list of errors from the compilation info log. Sometimes, errors occur
well before their effects are felt, and with judicious use of this error checking
function, you should be able to narrow down what the real error is and where
it occurs.
void
CheckGlErrors( const char* caller )
{
unsigned int gle = glGetError( );
Search WWH ::




Custom Search