title: How to implement iGlobalTime for a GLSL fragment shader in C++?
body: <p>Currently I have a tiny C++ application which display a triangle by these two shaders:</p>
  
  <p>Vertex shader:</p>
  
  <pre><code>static const char *vertex_shader_glsl = \
  "#version 430\n"
  
  "layout (location=0)in vec2 inVer;"
  "out vec2 p;"
  "out gl_PerVertex"
  "{"
  "vec4 gl_Position;"
  "};"
  
  "void main()"
  "{"
  "gl_Position=vec4(inVer,0.0,1.0);"
  "p=inVer;"
  "}";
  </code></pre>
  
  <p>Fragment shader:</p>
  
  <pre><code>#version 430
  
  
  out vec4 fragColor;
  in vec2 fragCoord;
  vec2 iResolution;
  //uniform float iGlobalTime;
  float a = -2;
  
  void main()
  {
      a = sin(-2);
      //Colors
      vec3 fgColor = vec3(0.741, 0.635, 0.471);
      vec3 bgColor = vec3(0.192, 0.329, 0.439);
  
      //Triangle barycentric coordinates defined on screen space
  
  
      vec2 t0 = vec2(0.25, 0);
      vec2 t1 = vec2(0.75, 0.25);
      vec2 t2 = vec2(0.50, 0.85);
      vec2 tCentroid  = (t0 + t1 + t2)/3.0;    
      //Compute UV coordinates
      vec2 uv = fragCoord.xy;
  
      vec2 v0 = t2 - t0;
      vec2 v1 = t1 - t0;
      vec2 v2 = uv - t0;
  
      //Compute barycentric coordinates 
      float dot00 = dot(v0, v0);
      float dot01 = dot(v0, v1);
      float dot02 = dot(v0, v2);
      float dot11 = dot(v1, v1);
      float dot12 = dot(v1, v2);
  
      float invDenom = 1.0/(dot00 * dot11 - dot01 * dot01);
      float baryX = (dot11 * dot02 - dot01 * dot12) * invDenom;
      float baryY = (dot00 * dot12 - dot01 * dot02) * invDenom;
  
      if((baryX &gt;= 0.0) &amp;&amp; (baryY &gt;= 0.0) &amp;&amp; (baryX + baryY &lt;= 1.0)) {
          fragColor = vec4(fgColor, 1.0);
      } else {
          fragColor = vec4(bgColor, 1.0);
      }
  }
  </code></pre>
  
  <p>This two shaders display a simple triangle:</p>
  
  <p><a href="https://i.stack.imgur.com/M3js4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/M3js4.png" alt="enter image description here"></a></p>
  
  <p>However I would like to rotate this triangle so I would need some timer implmemntation (iGlobalTime). </p>
  
  <p>I mean, I know that I would need something like this:
  <a href="https://www.shadertoy.com/view/Xtt3WX" rel="nofollow noreferrer">https://www.shadertoy.com/view/Xtt3WX</a></p>
  
  <p>However I cannot copy-paste the code from the link above, since I'm unable to use iGlobalTime in my C++ project. How to update the shaders above to be able to rotate the triangle based on the system time? How to implement iGlobalTime in a very basic C++ application?</p>
  
  <p>===========================</p>
  
  <h1>          EDITED</h1>
  
  <p>I've updated:</p>
  
  <p>ext.h:</p>
  
  <pre><code>...
      #ifdef DEBUG
      #define NUMFUNCTIONS 14 // &lt;&lt;== HERE
      #else
      #define NUMFUNCTIONS 12 // &lt;&lt;== HERE
      #endif
  
      extern void *myglfunc[NUMFUNCTIONS];
  
      #define glCreateShaderProgramv         ((PFNGLCREATESHADERPROGRAMVPROC)myglfunc[0])
      #define glGenProgramPipelines          ((PFNGLGENPROGRAMPIPELINESPROC)myglfunc[1])
      #define glBindProgramPipeline          ((PFNGLBINDPROGRAMPIPELINEPROC)myglfunc[2])
      #define glUseProgramStages             ((PFNGLUSEPROGRAMSTAGESPROC)myglfunc[3])
      #define glProgramUniform4fv            ((PFNGLPROGRAMUNIFORM4FVPROC)myglfunc[4])
      #define glGenFramebuffers              ((PFNGLGENFRAMEBUFFERSPROC)myglfunc[5])
      #define glBindFramebuffer              ((PFNGLBINDFRAMEBUFFERPROC)myglfunc[6])
      #define glTexStorage2D                 ((PFNGLTEXSTORAGE2DPROC)myglfunc[7])
      #define glDrawBuffers                  ((PFNGLDRAWBUFFERSPROC)myglfunc[8])
      #define glFramebufferTexture           ((PFNGLFRAMEBUFFERTEXTUREPROC)myglfunc[9])
      #define glProgramUniform1f             ((PFNGLPROGRAMUNIFORM1FPROC)myglfunc[10]) // &lt;&lt;== ADDED NEW LINE HERE
      #define glGetUniformLocation           ((PFNGLGETUNIFORMLOCATIONPROC)myglfunc[11]) // &lt;&lt;== ADDED NEW LINE HERE
  
      #ifdef DEBUG
      #define glGetProgramiv          ((PFNGLGETPROGRAMIVPROC)myglfunc[12])
      #define glGetProgramInfoLog     ((PFNGLGETPROGRAMINFOLOGPROC)myglfunc[13])
      #endif
  ...
  </code></pre>
  
  <p>updated ext.cpp:</p>
  
  <pre><code>...
  static char *strs[] = {
      "glCreateShaderProgramv",
      "glGenProgramPipelines",
      "glBindProgramPipeline",
      "glUseProgramStages",
      "glProgramUniform4fv",
      "glProgramUniform1fv",
      "glGenFramebuffers",
      "glBindFramebuffer",
      "glTexStorage2D",
      "glDrawBuffers",
      "glFramebufferTexture",
      "glProgramUniform1f",        // &lt;&lt;== ADDED NEW LINE HERE
      "glGetUniformLocation",      // &lt;&lt;== ADDED NEW LINE HERE
  
      #ifdef DEBUG
      "glGetProgramiv",
      "glGetProgramInfoLog",
      #endif
      };
  ...
  </code></pre>
  
  <p>updated intro.cpp:</p>
  
  <pre><code>...
      void intro_do(long time)
      {
      ...
      glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
          glBindProgramPipeline(renderingPipeline);
          // Set fparams to give input to shaders
  
          // Render
          glProgramUniform4fv(fragmentShader, 0, 4, fparams);
          glProgramUniform1f(fragmentShader, glGetUniformLocation(fragmentShader, "iGlobalTime"), time*1000); // &lt;&lt;== ADDED NEW LINE HERE
          glRects(-1, -1, 1, 1); // Deprecated. Still seems to work though.
  
      ...
      }
  </code></pre>
  
  <p>Application now runns, but crashes immediatelly saying: "Unhandled exception at 0x7542CB49 in 4kIntro.exe: 0xC0000005: Access violation reading location 0x00000000."</p>