PDA

View Full Version : Masking to show player color....problem please help



glBomb
12-27-2006, 11:54 PM
OpenGL,Ortho,2D game:

Ok i have these units in my 2d game i want to display using various player colors.However the unit image is just 1 image.The pixels where player color should appear are known/marked out by a specific color.The unit image is displayed as a textured quad. I want to use only the unit image & say some mask to display any player color in the unit image.

So i thought the mask could be white only where player color should be present(black otherwise) & of same dimension as the unit image.

Now if i multiply a texture of dimensions=unit image but color=player color with mask, i will get a black image with the player color present in the exact positions i want them in the unit image. Now how to superimpose this image on the unit image to get the player colors there as well?.

Anyone has a better idea on how to do this whole thing? i want masks of 1 bit depth only.How to store such masks in video memory so they occupy 1 bit depth only...textures have to be 8bpp at least i think

k_szczech
12-28-2006, 01:24 AM
Yes, GPU is free to choose internal format of texture so even if you create 1-bit texture it will most likely be stored as 8-bit.

As for combining player image with masked player color I have two suggestions for you:

1.
Put mask to alpha-only texture - when rendering use alpha blending or alpha test (or both):

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glAlphaFunc(GL_GREATER, 0.01f);
glEnable(GL_BLEND);
glEnable(GL_ALPHA_TEST);2.
Put mask to luminance only texture (this is what you currently do), and use the following blend function:

glBlendFunc(GL_ONE, GL_ONE);
glEnable(GL_BLEND);Additionally, texture with player image should have black pixels where mask is white (it should be pre-multiplied by inverse of mask).

First solution will be faster if your players occupy lots of pixels on the screen since it skips invisible pixels using alpha test.