title: Generating points incorrectly in OpenGL
body: <p>I am using OpenGL ES in Android Studio. I have an empty texture of viewport size. Its color is set as follows.</p>
  <p>Few parallel red color lines of gradient 1 are drawn on a white background. I used fragment shader to generate points and set color. (For some reason I didn't use GL_POINTS to draw points.) The points are generated at adjacent pixels to create lines. I need the point size of 40 so that 40x40 pixels around each point are set to red, while other pixels are set to white.</p>
  <p>This is how the empty texture was created and bound to framebuffer.</p>
  <pre><code>    glGenFramebuffers(1, &amp;fbo);  
      glGenTextures(1, &amp;targetTexture);
  
      glBindFramebuffer(GL_FRAMEBUFFER, fbo);
      glBindTexture(GL_TEXTURE_2D, targetTexture);
      glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, screenWidth, screenHeight, 0, GL_RGBA, GL_FLOAT, nullptr);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
      glBindTexture(GL_TEXTURE_2D, 0);
      glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, targetTexture, 0);
      glBindFramebuffer(GL_FRAMEBUFFER, 0);  
  </code></pre>
  <p>Here are the shaders.</p>
  <p>Vertex shader :</p>
  <pre><code>    #version 310 es
      layout (location = 0) in vec4 vPosition; //4 corners of viewport
      void main(){
         gl_Position = vPosition;
      };  
  </code></pre>
  <p>Fragment shader :</p>
  <pre><code>    #version 310 es
      precision highp float;
      out vec4 outColor;
      void main(){
         bool isColoured = false;
         for(int j=100; j&lt;=1700; j=j+200){
            for(int i=j; i&lt;=j+1000; i++){
               float deltaX = gl_FragCoord.x - float(i);
               float deltaY = gl_FragCoord.y - (float(i) - (float(j)-100.0)); 
  
               if(abs(deltaX) &lt;= 20.0 &amp;&amp; abs(deltaY) &lt;= 20.0 &amp;&amp; isColoured == false){  
                  isColoured = true;
               }
            }
         }
         if(isColoured){
            outColor = vec4(1.0, 0.0, 0.0, 1.0);
         }else{
            outColor = vec4(1.0, 1.0, 1.0, 1.0);
         }
      };  
  </code></pre>
  <p>After a definite boundary in the horizontal direction, the expected behavior of lines are begun to collapse. This is the correct behavior up to that point.</p>
  <p>Correct region<br />
  <a href="https://i.stack.imgur.com/gFsAu.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gFsAu.jpg" alt="Correct region" /></a></p>
  <p>Like this after that.</p>
  <p>Incorrect region
  <a href="https://i.stack.imgur.com/AbaXS.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AbaXS.jpg" alt="Incorrect region" /></a></p>
  <p>Zoomed incorrect region<br />
  <a href="https://i.stack.imgur.com/0HL2f.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0HL2f.png" alt="Zoomed incorrect region" /></a></p>
  <p>The points have shifted more than 1 pixel in both directions.<br />
  How can I get rid of this issue?</p>
  <p>Thank you in advance.</p>