Reading texture colors values
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(I'm using tga)?
The file format doesn't make a difference. If you keep the buffer you pass to glTexImage2D around, you can simply examing the alpha value at the appropriate pixel location.
ThemsAllTook Wrote:The file format doesn't make a difference. If you keep the buffer you pass to glTexImage2D around, you can simply examing the alpha value at the appropriate pixel location.
I'm not sure I understand quite what you're saying(my understanding of opengl is terrible). Are you saying for me to use the coord on the selected quad as an index to it's texture's image data? And if so, how do I parse through that data to retrieve the alpha values?
you can just call glReadPixels to get the color of a pixel on screen.
Sir, e^iπ + 1 = 0, hence God exists; reply!
unknown Wrote:you can just call glReadPixels to get the color of a pixel on screen.
Yeah but when Im trying to get the alpha value of a sprite, ill end up getting the alpha value of the tile under the sprite, right?
Yeah, you don't want to call glReadPixels. You want to read it out of your original image.
Assuming that your texture is a vanilla 32bit RGBA image, then you would do the following.
Assuming that your texture is a vanilla 32bit RGBA image, then you would do the following.
Code:
unsigned char *pixels; // pointer to your texture data
unsigned char alpha = pixels[4*(y*width + x) + 3];Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Skorche Wrote:Code:
unsigned char *pixels; // pointer to your texture data
unsigned char alpha = pixels[4*(y*width + x) + 3];
That's what I was looking for, thanks.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| passing values from vertex to fragment shader | Sumaleth | 6 | 8,636 |
Feb 18, 2011 01:54 AM Last Post: Holmes |
|
| Changing Pixel Values using CG | LIPH700 | 1 | 3,756 |
Nov 25, 2010 03:17 PM Last Post: SethWillits |
|
| Lighting and changing texture colors in OpenGL | agreendev | 2 | 6,116 |
Aug 13, 2010 03:47 PM Last Post: agreendev |
|
| "Inconsistent set of values to create NSBitmapImageRep" Help! | Joseph Duchesne | 2 | 4,983 |
Sep 30, 2005 05:32 PM Last Post: Joseph Duchesne |
|
| Passing values to SDL_LoadBMP strangeness | Lunatic | 0 | 2,271 |
Sep 7, 2005 08:49 PM Last Post: Lunatic |
|

