| 134 |   |  6. Change background to {{{glClearColor(0.9,1,1,1.0);}}} | 
                      
                      
                        |   | 134 |  6. Change background to {{{glClearColor(0.9,1,1,1.0);}}} and suggest initial window in `main()` | 
                      
                        |   | 135 |   {{{ | 
                      
                        |   | 136 |   #!c | 
                      
                        |   | 137 |   glutInitWindowSize(512, 512); | 
                      
                        |   | 138 |   glutInitWindowPosition((glutGet(GLUT_SCREEN_WIDTH)-512)/2, | 
                      
                        |   | 139 |                          (glutGet(GLUT_SCREEN_HEIGHT)-512)/2); | 
                      
                        |   | 140 |   }}} | 
                      
            
                      
                        | 279 |   |   For general (core) OpenGL errors we can use the following utility at suspicious places. | 
                      
                        | 280 |   |   {{{ | 
                      
                        | 281 |   |   #!c | 
                      
                        | 282 |   |      GLenum errCode; | 
                      
                        | 283 |   |      if ((errCode = glGetError()) != GL_NO_ERROR) { | 
                      
                        | 284 |   |         const GLubyte *errString = gluErrorString(errCode); | 
                      
                        | 285 |   |         fprintf (stderr, "OpenGL Error: %s\n", errString); | 
                      
                        | 286 |   |      } | 
                      
                        | 287 |   |   }}} | 
                      
                        | 288 |   |  2. Introduce vertex temperature with additional array | 
                      
                        | 289 |   |   {{{ | 
                      
                        | 290 |   |   #!c | 
                      
                        | 291 |   |   GLfloat vertex_temperature[] = {0, 0.5, 1, 0.7, 0.2, 0.9}; | 
                      
                        | 292 |   |   }}} | 
                      
                        | 293 |   |   and replace shaders with | 
                      
                      
                        |   | 283 |   For general (core) OpenGL errors we can use the following `glcheck()` utility at suspicious places. | 
                      
                        |   | 284 |   {{{ | 
                      
                        |   | 285 |   #!c | 
                      
                        |   | 286 |   #define glcheck() {GLenum s; if ((s=glGetError()) != GL_NO_ERROR) \ | 
                      
                        |   | 287 |                   fprintf (stderr, "OpenGL Error: %s at line %d\n", \ | 
                      
                        |   | 288 |                            gluErrorString(s),  __LINE__);} | 
                      
                        |   | 289 |   }}} | 
                      
                        |   | 290 |  2. Introduce vertex temperature with additional array and buffer at the end off `init()` | 
                      
                        |   | 291 |   [[Image(temperature.png,right)]] | 
                      
                        |   | 292 |   {{{ | 
                      
                        |   | 293 |   #!c | 
                      
                        |   | 294 |   GLfloat vertex_temperature[] = {0, 1, 0.2, 0.1, 0.5, 0.9}; | 
                      
                        |   | 295 |   glBindBuffer(GL_ARRAY_BUFFER, Buffers[TempBuffer]); | 
                      
                        |   | 296 |   glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_temperature), | 
                      
                        |   | 297 |                vertex_temperature, GL_STATIC_DRAW); | 
                      
                        |   | 298 |   glVertexAttribPointer(tPosition, 1, GL_FLOAT, GL_FALSE, 0, NULL); | 
                      
                        |   | 299 |   glEnableVertexAttribArray(tPosition);//toggle this | 
                      
                        |   | 300 |   }}} | 
                      
                        |   | 301 |   and adding corresponding IDs to `VAOs` and buffers. Replace shaders with | 
                      
            
                      
                        | 302 |   | "vec3 Cool = vec3(0, 0, 1);" // Red | 
                      
                        | 303 |   | "vec3 Hot  = vec3(1, 0, 1);" // Blue | 
                      
                        | 304 |   | "void main() | 
                      
                        | 305 |   | "{" | 
                      
                        | 306 |   | "  vec3 color = mix(Cool, Hot, Temperature);" // use the built-in mix() function | 
                      
                        | 307 |   | "  gl_FragColor = vec4(color, 1.0);"          // append alpha channel | 
                      
                        | 308 |   | "}" | 
                      
                        | 309 |   | };  | 
                      
                        | 310 |   |   }}} | 
                      
                      
                        |   | 315 |   "vec3 Cool = vec3(0, 0, 1);" // Red | 
                      
                        |   | 316 |   "vec3 Hot  = vec3(1, 0, 0);" // Blue | 
                      
                        |   | 317 |   "varying float t;" // Interpolated by fragment | 
                      
                        |   | 318 |   "void main()" | 
                      
                        |   | 319 |   "{" | 
                      
                        |   | 320 |   "  vec3 color = mix(Cool, Hot, t);"  // use the built-in mix() function | 
                      
                        |   | 321 |   "  gl_FragColor = vec4(color, 1.0);" // append alpha channel | 
                      
                        |   | 322 |   "}" | 
                      
                        |   | 323 | }; | 
                      
                        |   | 324 |   }}} | 
                      
                        |   | 325 |   What happens if we don't enable temperature vertex array? Confer [attachment:temperature.c] attached if having troubles. | 
                      
                        |   | 326 |  3. Add additional custom vertex array for the pressure. Change the temperature array to have values in Celsius for water boiling range [0-100]°C. Pressure should be in the range of [0-1] MPa. Scaling to color range [0-1] should be done in shaders. Toggle between them with the keyboard event by using the keys `'p'` and `'t`' that {{{glEnableVertexAttribArray()}}} and {{{glDisableVertexAttribArray()}}} corresponding vertex attribute arrays. | 
                      
                        |   | 327 |    |