I have a terrain and entities(npc, house...).

I'm able to convert screen coordinates to world coordinates with the glReadPixels function:

glReadPixels(mousePosition.x, mousePosition.y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z);
// of course its not just that...

My character can move over that terrain without problem, but I'm not able to move when the mouse is over a big house and I try to move "behind" that house.

Do you know how I can avoid entities when converting screen coordinates to world coordinates ?

  • 2
    \$\begingroup\$ don't render the entities in the pass that creates that depth buffer \$\endgroup\$ – ratchet freak Dec 12 '15 at 13:03

Your depth buffer does not contain "entities". It contains the stuff you rendered. So if you read the depth buffer, you will read the depth for the closest stuff you rendered.

So either you make a special depth-only rendering pass that does not contain "entities", or you're going to have to do something else to convert from the user's selected location to a world-space position. And generally speaking, games use something else. Probably a ray-trace, but depending on the nature of your world, even that may not be necessary.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.