Changes between Version 10 and Version 11 of tutorial


Ignore:
Timestamp:
Jun 27, 2013, 12:38:41 AM (6 years ago)
Author:
leon
Comment:

Ex2

Legend:

Unmodified
Added
Removed
Modified
  • tutorial

    v10 v11  
    132132
    133133== Modern OpenGL ==
    134 Create {{{triangle.c}}} and update {{{Makefile}}} [[Image(triangle.png,right)]]
     134[[Image(triangle.png,right)]]
    135135We extend previous exercise with example that introduces OpenGL 3.x techniques:
    136  * OpenGL Shading Language
     136 * OpenGL Shading Language where simple vertex and fragment shader are required.
    137137 * Vertex Buffer Objects stored in GPU
    138 
     138Create {{{triangle.c}}} and update {{{Makefile}}} with new target
    139139{{{
    140140#!sh
     
    229229}
    230230}}}
     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  }}}