0

In my program I've loaded a mesh model on my canvas and initially read its depth values with glReadPixels.

This code is written after gl.glFlush() in the display function:

FloatBuffer depth_mann = FloatBuffer.allocate(width*height);

...

gl.glPixelStorei(GL2.GL_PACK_ROW_LENGTH, width);
gl.glPixelTransferf(GL2.GL_DEPTH_SCALE, 1.0f);
gl.glPixelTransferf(GL2.GL_DEPTH_BIAS, 0.f); 
gl.glReadPixels(0, 0, width, height, GL2.GL_DEPTH_COMPONENT, GL2.GL_FLOAT, depth_mann); 

Later I accessed the depth values to be used in a glUnproject and assign the resulting z-value to a set of vertices, and added with an offset, the vertices will lie on top of the mesh model. Sort of elevated. In other words, I'm trying to come up with an inflation function. However, not all of the vertices are elevated, and after a bit of testing, it turns out that the depth values returned by glReadPixels are not always the same.

Now, I'm trying to figure out what's wrong for four days but I think it's time for some help. I feel like there are things that I should know which I don't know and your help in filling those missing pieces will be appreciated. Thanks in advance!

Sunny Hill
  • 21
  • 4
  • 1
    Careful with floatbuffers, make sure they use `nativeOrder` or allocate them via `GLBuffers.newDirectFloatBuffer` – elect Feb 24 '16 at 18:29
  • I advise you to look at this example: http://jogamp.org/jogl-demos/src/demos/misc/Picking.java The depth values aren't linearly distributed and I fixed a bug in the quoted example several years ago. I had a similar problem. – gouessej Feb 24 '16 at 22:01

0 Answers0