From afbdd371212aa95c87252fdd09d07c378d59c9be Mon Sep 17 00:00:00 2001 From: dcnieho Date: Fri, 15 Jun 2012 05:54:44 +0000 Subject: [PATCH] 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 --- freeglut/freeglut/progs/demos/shapes/shapes.c | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/freeglut/freeglut/progs/demos/shapes/shapes.c b/freeglut/freeglut/progs/demos/shapes/shapes.c index c6527fc..4f0e904 100644 --- a/freeglut/freeglut/progs/demos/shapes/shapes.c +++ b/freeglut/freeglut/progs/demos/shapes/shapes.c @@ -50,6 +50,15 @@ #include #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, * 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; } + checkError ("getAttribOrUniformLocation"); } GLuint program; @@ -305,12 +315,16 @@ void compileAndCheck(GLuint shader) fprintf (stderr, "compile log: %s\n", infoLog); free (infoLog); } + checkError ("compileAndCheck"); } GLuint compileShaderSource(GLenum type, GLsizei count, const ourGLchar **string) { GLuint shader = gl_CreateShader (type); gl_ShaderSource (shader, count, string, NULL); + + checkError ("compileShaderSource"); + compileAndCheck (shader); return shader; } @@ -329,6 +343,7 @@ void linkAndCheck(GLuint program) fprintf (stderr, "link log: %s\n", infoLog); free (infoLog); } + checkError ("linkAndCheck"); } void createProgram(GLuint vertexShader, GLuint fragmentShader) @@ -340,6 +355,9 @@ void createProgram(GLuint vertexShader, GLuint fragmentShader) if (fragmentShader != 0) { gl_AttachShader (program, fragmentShader); } + + checkError ("createProgram"); + linkAndCheck (program); } @@ -353,6 +371,8 @@ void initShader(void) GLuint fragmentShader = compileShaderSource (GL_FRAGMENT_SHADER, fragmentShaderLines, fragmentShaderSource); + checkError ("initShader - 1"); + createProgram (vertexShader, fragmentShader); gl_UseProgram (program); @@ -370,6 +390,8 @@ void initShader(void) shaderReady = -1; else shaderReady = 1; + + checkError ("initShader - 2"); } /* @@ -627,6 +649,8 @@ static void display(void) gl_UseProgram (0); glutSetVertexAttribCoord3(-1); glutSetVertexAttribNormal(-1); + + checkError ("display"); } else {