title: OpenGL ES 2.0 - GL_POINTS and Stencil Buffer
body: <p>I am trying to draw a texture in OpenGL ES 2.0 using GL_POINTS by applying a stencil buffer. The stencil buffer should come from a texture. I am rendering the results to another texture and then presenting the texture to screen. Here is my code for rendering to texture:</p>
  
  <pre><code>//Initialize buffers, initialize texture, bind frameBuffer
  .....
  glClearStencil(0);
  glClear (GL_STENCIL_BUFFER_BIT);
  
  glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE );
  glEnable(GL_STENCIL_TEST);
  glStencilFunc(GL_ALWAYS, 1, 1);
  glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
  glBindTexture(GL_TEXTURE_2D, stencil);
  
  glUseProgram(program[PROGRAM_POINT].id);
  glDrawArrays(GL_POINTS, 0, (int)vertexCount);
  
  glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
  glStencilFunc(GL_NEVER, 0, 1);
  glStencilOp(GL_REPLACE, GL_KEEP, GL_KEEP);
  
  glBindTexture(GL_TEXTURE_2D, texture);
  glUseProgram(program[PROGRAM_POINT].id);
  glDrawArrays(GL_POINTS, 0, (int)vertexCount);
  glDisable(GL_STENCIL_TEST);
  ....
  //Render texture to screen
  </code></pre>
  
  <p>The result I am getting is just my texture being drawn without any masking applied from the stencil. I had a few questions regarding this issue:</p>
  
  <ol>
  <li>Is is possible to use a stencil buffer with GL_POINTS?</li>
  <li>Is is possible to use a stencil buffer when rendering to a texture?</li>
  <li>Does the stencil texture have to have any special properties (solid colour, internal format...etc)?</li>
  <li>Are there any apparent mistakes with my code?</li>
  </ol>
  
  <p>This is the result I am looking for:
  <img src="https://i.stack.imgur.com/J3TGt.png" alt="enter image description here"></p>
  
  <p>UPDATE:</p>
  
  <p>My problem, as pointed out by the selected answer, was primarily that I did not attach the stencil to the stencil attachment of the FBO:</p>
  
  <pre><code>glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
                        GL_RENDERBUFFER, stencilBufferId);
  </code></pre>
  
  <p>I did not know that it was required when rendering to a texture. Secondly I was not using the proper stencil test. </p>
  
  <pre><code>glStencilFunc(GL_EQUAL, 1, 1);
  glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
  </code></pre>
  
  <p>Did the job.</p>