My aim is to determine a sequence of (stencil) operations so that regardless of the order in which objects are rendered I can end up with the visible (non-occluded) part of any object (believe that I am looking at rendering objects that pass the stencil test but do not pass the depth test).

I have the following code:

```
glStencilMask(0xFF)
glStencilFunc(GL_ALWAYS, 1, 0xFF) # All fragments will pass
glStencilOp(GL_KEEP, GL_REPLACE, GL_KEEP)
# cube 1. Large cube that I want to render to the stencil
glBindVertexArray(cubeVAO)
glActiveTexture(GL_TEXTURE0)
glBindTexture(GL_TEXTURE_2D, cubeTexture)
model = glm.mat4(1.0)
model = glm.translate(model, glm.vec3(0.0, 0.0, -0.75))
shader.setMat4("model", model)
glDrawArrays(GL_TRIANGLES, 0, 36)
# Stop rendering to the stencil
glStencilMask(0x00)
# cube 2
scale = 0.35
model = glm.mat4(1.0)
model = glm.scale(model, glm.vec3(scale, scale, scale))
model = glm.translate(model, glm.vec3(0.0, 0, 2.0))
shader.setMat4("model", model)
glDrawArrays(GL_TRIANGLES, 0, 36)
glBindVertexArray(0)
```

Here are two renderings. The one on the left shows distance to the two cubes (and a floor). The one to the right shows what is the result of the stencil operations above.

The small cube that we can see on the left is clearly in front of the large cube yet the output I get on the right does not seem to correspond at all with what I would expect based on the left image. I am using pyOpengl and I am reading the results from the stencil buffer into a numpy array (for those that are familiar with these). I use the following code to do this (I am including it here in case I am inadvertendly changing something),

```
stencil = glReadPixels(0,0, SCR_WIDTH, SCR_HEIGHT, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE)
stencil = np.fliplr(np.frombuffer(stencil, dtype=np.uint8).reshape((800,-1)))
```

I am trying to figure out this disparity.