Zhang
Zhang

Reputation: 11607

glReadPixels on separate layers

I'll get straight to the point :)

enter image description here

From the above 480 x 320 diagram, I am thinking I can detect collision on pixel level like a worm game.

What I want to know is how to sample pixels on separate layers. As you can see in the diagram, as the worm is falling, I want to only sample the black pixels with glReadPixels() to see if the worm is standing (colliding) with any terrain but when I last tried it, glReadPixels() samples all pixels on screen, without any ideas of "layers".

The white pixel is the background that should not be part of the sampling.

Am I perhaps suppose to have a black and white copy of my terrain on a separate buffer and call glReadPixels() on that separate buffer so that the background images (white pixels) won't get sampled?

Before I was drawing my terrain on the screen in the same buffer/context where I draw my background image.

Any ideas?

Upvotes: 0

Views: 245

Answers (1)

Trax
Trax

Reputation: 1910

What read pixels does is read back the binded buffer, since the buffer is the output of all your compositions, will obviously contain all the data your wrote and doesn't understand you logic arrangement into layer. You can try drawing your terrain into the stencil buffer and read back only that. Use GL_DEPTH_STENCIL (format parameter).

Upvotes: 1

Related Questions