Example/GLSL Shader Compile Error Testing

From OpenGL Wiki
< Example
Revision as of 04:02, 22 January 2013 by Alfonse (talk | contribs) (Example page for shader compiler error testing.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Shader compilation error checking.

GLuint shader = glCreateShader(...);

//Get strings for glShaderSource.
glShaderSource(shader, ...);

glCompileShader(shader);

GLint isCompiled = 0;
glGetShaderiv(shader, GL_COMPILE_STATUS, &isCompiled);
if(isCompiled == GL_FALSE)
{
	GLint maxLength = 0;
	glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &maxLength);

	//The maxLength includes the NULL character
	std::vector<char> errorLog(maxLength);
	glGetShaderInfoLog(vertexshader, maxLength, &maxLength, &errorLog[0]);

	//Provide the infolog in whatever manor you deem best.
	//Exit with failure.
	return;
}

//Shader compilation is successful.