| 231 | |
| 232 | == Exercises #2 == |
| 233 | 1. To be able to continue and not get lost introduce shader compiler logs in case of compilation errors by adding the following code into {{{setShaders()}} right at after vertex shader compilation: |
| 234 | {{{ |
| 235 | #!c |
| 236 | GLint compiled; |
| 237 | glGetShaderiv(v, GL_COMPILE_STATUS, &compiled ); |
| 238 | if ( !compiled ) { |
| 239 | GLsizei len; |
| 240 | glGetShaderiv( v, GL_INFO_LOG_LENGTH, &len ); |
| 241 | GLchar* log = malloc(sizeof(GLchar)*(len+1)); |
| 242 | printf("Shader compilation failed: %s\n", log); |
| 243 | free(log); |
| 244 | } |
| 245 | }}} |
| 246 | Do not forget to repeat the same thing for fragment shader. |
| 247 | 2. Add linker debugging |
| 248 | {{{ |
| 249 | #!c |
| 250 | GLint linked; |
| 251 | glGetProgramiv(p, GL_LINK_STATUS, &linked ); |
| 252 | if ( !linked ) { |
| 253 | GLsizei len; |
| 254 | glGetProgramiv( p, GL_INFO_LOG_LENGTH, &len ); |
| 255 | GLchar* log = malloc(sizeof(GLchar)*(len+1)); |
| 256 | glGetProgramInfoLog( p, len, &len, log ); |
| 257 | printf("Shader linking failed: %s\n", log); |
| 258 | free(log); |
| 259 | } |
| 260 | }}} |
| 261 | 3. For general (core) OpenGL errors we can use the following utility at suspicious places. |
| 262 | {{{ |
| 263 | #!c |
| 264 | GLenum errCode; |
| 265 | if ((errCode = glGetError()) != GL_NO_ERROR) { |
| 266 | const GLubyte *errString = gluErrorString(errCode); |
| 267 | fprintf (stderr, "OpenGL Error: %s\n", errString); |
| 268 | } |
| 269 | }}} |