Jump to content
  • Advertisement
Sign in to follow this  
Aleister55

reading texture alpha values

This topic is 4161 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm working on enabling the player to select objects(textured quads) in my 2d game. So first, I check if a mousedown has occurred in the bounding rect of the quad, and if it has, I want to check the corresponding color value of the texture's pixel which I clicked, for transparency(the alpha value). How do I do this?

Share this post


Link to post
Share on other sites
Advertisement
It's not a GL problem.
You need to know where on the polygon it was clicked and use barycentric coordinates to figure which st value is present where the user clicked.
If you have a 2D game, it will be easy to calculate this stuff.

Share this post


Link to post
Share on other sites
I must say, that was a particularly vague and unhelpful comment. I should have been more specific I guess. Here is my pseudo-code up until the point:

point world_click = get_world_click();
quad_click.x = world_click.x - quad.x;
quad_click.y = world_click.y - quad.y;

Now that I have quad_click, how do I figure out the alpha value of the corresponding texel for the point on the quad which the player clicked?

Share this post


Link to post
Share on other sites
The answer is in my previous post : barycentric coordinates
You need to know on which triangle the user clicked on, where exactly it was on the triangle. The mathematics involved with barycentric coordinates can be used to get the st coordinates.

Convert the st coordinates : just multiply by your texture dimension.
So if your texture is in RAM, you'll get the RGBA of the texture.

Or you could keep it simple if you are doing a 2D application and you just have rectangles. No need to worry about the complex math with barycentric coordinates.

Share this post


Link to post
Share on other sites
I undertsand how to get thebarycentric coordinates, my only question is(my grasp of opengl is extremely limited) how do I get the rgba value? Do I call some opengl function or what? Could you please show me some pseudo-code or something?

Thanks.

Share this post


Link to post
Share on other sites
glReadixels will work if the framebuffer has an alpha channel but why depend on system settings?
It's more reliable to store your textures in RAM. If you don't have it, use glGetTexImage

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!