title: Compute Shader OpenGL Write to Texture
body: <p>I want to write to a texture with a compute shader. for testing purposes i only want to write blue pixels to a given empty texture.<br>
  I am only getting a black screen.
  I will show the relevant part of my code</p>
  
  <p>Vertex Shader</p>
  
  <pre><code>#version 330 core
  layout (location = 0) in vec2 aPos; 
  layout (location = 1) in vec2 aTexCoords;
  
  out vec2 TexCoords;
  
  void main()
  {
     TexCoords = aTexCoords;
     gl_Position = vec4(aPos.x, aPos.y, 0.0, 1.0);
  }
  </code></pre>
  
  <p>Fragement Shader</p>
  
  <pre><code>#version 330 core
  out vec4 FragColor;
  
  in vec2 TexCoords;
  
  uniform sampler2D screenTexture;
  
  void main()
  {
      vec3 col = texture(screenTexture, TexCoords).rgb;
      FragColor = vec4(col, 1.0);
  }
  </code></pre>
  
  <p>Compilation Compute Shader (all used variables are members of my class)
  //Update as Rabbid76 suggested, still not working</p>
  
  <pre><code>cshader = glCreateShader(GL_COMPUTE_SHADER);
  const char *csSrc[] = {
      "#version 440\n",
      "layout (binding = 0, rgba32f) uniform image2D destTex;\
       layout (local_size_x = 16, local_size_y = 16, local_size_z = 1) in;\
       void main() {\
             ivec2 storePos = ivec2(gl_GlobalInvocationID.xy);\
             imageStore(destTex, storePos, vec4(0.0,0.0,1.0,1.0));\
      }"
  };
  glShaderSource(cshader, 2, csSrc, NULL);
  glCompileShader(cshader);
  cshaderprogram = glCreateProgram();
  glAttachShader(cshaderprogram, cshader);
  glLinkProgram(cshaderprogram);
  </code></pre>
  
  <p>Creating Output Texture</p>
  
  <pre><code>glGenTextures(1, &amp;this-&gt;outputTexture);
  glActiveTexture(GL_TEXTURE0);
  glBindTexture(GL_TEXTURE_2D, this-&gt;outputTexture);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, width(), height(), 0, GL_RGBA32F, 
  GL_FLOAT, NULL);
  glBindImageTexture(0, this-&gt;outputTexture, 0, GL_FALSE, 0, GL_WRITE_ONLY, 
  GL_RGBA32F);
  </code></pre>
  
  <p>Drawing on Quad </p>
  
  <pre><code>glUseProgram(cshaderprogram);
  glUniform1i(0, 0);
  glActiveTexture(GL_TEXTURE0);
  glBindImageTexture(0, outputTexture, 0, GL_FALSE, 0, GL_WRITE_ONLY, 
  GL_RGBA32F);
  glDispatchCompute(width() / 16, height() / 16, 1);
  
  glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
  
  screenProgram.bind();
  glBindFramebuffer(GL_FRAMEBUFFER, 0);
  glBindVertexArray(screenVao);
  glActiveTexture(GL_TEXTURE0);
  glBindTexture(GL_TEXTURE_2D, outputTexture);
  glDrawArrays(GL_TRIANGLES, 0, 6);
  </code></pre>
  
  <p>I hope you guys can help me. if there are questions just ask them</p>