PDA

View Full Version : Examing pixels in 2D openGL game



glBomb
07-23-2006, 11:45 AM
I am working on a 2D game & using openGL with ortho view . I have these sprites which i display as textured quads. However some of these images i need to examine pixel by pixel looking for a specific color.Then instead of this color i put the appropriate 'Player Color' of the unit i am putting on screen. Imagine i have colors numbered from 0 to 255.
Then i have this special color 255 which when found in a pixel always results in the appropriate player color(say red/green/yellow for 3 players...which might be say the color 24/145/234 respec) being put in the frame buffer instead of the original pixel color. So basically i cant bind the texture right away. I need to EXAMINE EACH PIXELS & PUT THEM ON THE QUAD PIXEL BY PIXEL replacing the pixels color in the image with player color whereever a 255(indication of player color) is found.
But is this possible. What is the most fastest &most efficient way of doing this ? Could i simply write to a texture or something which i heard openGL can do. One thing is certain i need to access the pixels in a for-loop & write them out again...how hard will my frame rate be hit? i heard glDrawPixels() is slow...i need a fast method or maybe some sort of mask whatever

Korval
07-23-2006, 12:56 PM
What is the most fastest &most efficient way of doing this ?On the CPU.

Pixel-perfect collision detection is best not done on the GPU. The round-trip travel time from CPU-to-GPU-to-CPU is far more than just doing it in software.

Zengar
07-23-2006, 03:45 PM
A solution that comes to my mind is to use aplha-blending. You can define alpha of your '255' pixels to be 0 with the rest of the pixels using alpha of 255. You then bind a second texture (just solid color) and set the combiners to alpha blend. This way you will aotomatically get your result. Or, you can also use the alpha function and do it in two pass.