added bunch of error checks to shapes demo
git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@1345 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
parent
1bca835536
commit
afbdd37121
@ -50,6 +50,15 @@
|
|||||||
#include <crtdbg.h>
|
#include <crtdbg.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* report GL errors, if any, to stderr */
|
||||||
|
void checkError(const char *functionName)
|
||||||
|
{
|
||||||
|
GLenum error;
|
||||||
|
while (( error = glGetError() ) != GL_NO_ERROR) {
|
||||||
|
fprintf (stderr, "GL error 0x%X detected in %s\n", error, functionName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* OpenGL 2+ shader mode needs some function and macro definitions,
|
* OpenGL 2+ shader mode needs some function and macro definitions,
|
||||||
* avoiding a dependency on additional libraries like GLEW or the
|
* avoiding a dependency on additional libraries like GLEW or the
|
||||||
@ -282,6 +291,7 @@ GLint getAttribOrUniformLocation(const char* name, GLuint program, GLboolean isA
|
|||||||
|
|
||||||
return uniform;
|
return uniform;
|
||||||
}
|
}
|
||||||
|
checkError ("getAttribOrUniformLocation");
|
||||||
}
|
}
|
||||||
|
|
||||||
GLuint program;
|
GLuint program;
|
||||||
@ -305,12 +315,16 @@ void compileAndCheck(GLuint shader)
|
|||||||
fprintf (stderr, "compile log: %s\n", infoLog);
|
fprintf (stderr, "compile log: %s\n", infoLog);
|
||||||
free (infoLog);
|
free (infoLog);
|
||||||
}
|
}
|
||||||
|
checkError ("compileAndCheck");
|
||||||
}
|
}
|
||||||
|
|
||||||
GLuint compileShaderSource(GLenum type, GLsizei count, const ourGLchar **string)
|
GLuint compileShaderSource(GLenum type, GLsizei count, const ourGLchar **string)
|
||||||
{
|
{
|
||||||
GLuint shader = gl_CreateShader (type);
|
GLuint shader = gl_CreateShader (type);
|
||||||
gl_ShaderSource (shader, count, string, NULL);
|
gl_ShaderSource (shader, count, string, NULL);
|
||||||
|
|
||||||
|
checkError ("compileShaderSource");
|
||||||
|
|
||||||
compileAndCheck (shader);
|
compileAndCheck (shader);
|
||||||
return shader;
|
return shader;
|
||||||
}
|
}
|
||||||
@ -329,6 +343,7 @@ void linkAndCheck(GLuint program)
|
|||||||
fprintf (stderr, "link log: %s\n", infoLog);
|
fprintf (stderr, "link log: %s\n", infoLog);
|
||||||
free (infoLog);
|
free (infoLog);
|
||||||
}
|
}
|
||||||
|
checkError ("linkAndCheck");
|
||||||
}
|
}
|
||||||
|
|
||||||
void createProgram(GLuint vertexShader, GLuint fragmentShader)
|
void createProgram(GLuint vertexShader, GLuint fragmentShader)
|
||||||
@ -340,6 +355,9 @@ void createProgram(GLuint vertexShader, GLuint fragmentShader)
|
|||||||
if (fragmentShader != 0) {
|
if (fragmentShader != 0) {
|
||||||
gl_AttachShader (program, fragmentShader);
|
gl_AttachShader (program, fragmentShader);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkError ("createProgram");
|
||||||
|
|
||||||
linkAndCheck (program);
|
linkAndCheck (program);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -353,6 +371,8 @@ void initShader(void)
|
|||||||
GLuint fragmentShader =
|
GLuint fragmentShader =
|
||||||
compileShaderSource (GL_FRAGMENT_SHADER, fragmentShaderLines, fragmentShaderSource);
|
compileShaderSource (GL_FRAGMENT_SHADER, fragmentShaderLines, fragmentShaderSource);
|
||||||
|
|
||||||
|
checkError ("initShader - 1");
|
||||||
|
|
||||||
createProgram (vertexShader, fragmentShader);
|
createProgram (vertexShader, fragmentShader);
|
||||||
|
|
||||||
gl_UseProgram (program);
|
gl_UseProgram (program);
|
||||||
@ -370,6 +390,8 @@ void initShader(void)
|
|||||||
shaderReady = -1;
|
shaderReady = -1;
|
||||||
else
|
else
|
||||||
shaderReady = 1;
|
shaderReady = 1;
|
||||||
|
|
||||||
|
checkError ("initShader - 2");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -627,6 +649,8 @@ static void display(void)
|
|||||||
gl_UseProgram (0);
|
gl_UseProgram (0);
|
||||||
glutSetVertexAttribCoord3(-1);
|
glutSetVertexAttribCoord3(-1);
|
||||||
glutSetVertexAttribNormal(-1);
|
glutSetVertexAttribNormal(-1);
|
||||||
|
|
||||||
|
checkError ("display");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user