Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
How to colorize certain parts of a model - like RTS games have those team colors?

Ok, so here is my current situation. I have a player model, fully UV mapped, and textured. At first I made multiple bitmaps for the character representing multiple colors for each team in the game. (red, blue, green, yellow, etc) Well, as my player count build up, space lowers. So I needed to make a new method of keeping the game effecient, clean, and fast. So I thought of the idea of having a color mask (alpha map covering the areas to be colored). I am using OpenGL, and I just have NO idea on where to begin!

So I ask you, are there any libraries? methods? anything that could help me do this?

share|improve this question

marked as duplicate by Tetrad May 30 '12 at 23:35

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Are you doing this in fixed-function OpenGL or in shaders? – ChrisE Apr 18 '11 at 6:23

I recommend using the same idea that they use in movies - chroma key. Reserve one color that you don't otherwise use in your textures (e.g. green, blue, magenta). Let's call it the "reserved color." In the engine, make a matrix that rotates the "reserved color" onto the "player color" you wish to render at the moment.

Set this matrix as a pixel shader constant. In the pixel shader, compute the chroma of the pixel color and find its angle to the "reserved color's" chroma. Lerp the pixel color to the pixel color transformed by the matrix, according to how close the pixel's chroma is to the reserved color's chroma.

Why do this instead of using an alpha channel? Because when textures are DXT compressed, adding an alpha channel makes your texture 2x bigger. A matrix multiply and a little bit of trig in the pixel shader is a lot cheaper than reading 2x as much memory - and will become even cheaper as the years roll on.

share|improve this answer

you can make a model with some base color and replace that color with a shader.

color = texture_color(x,y);

if(color == base_color)
    color = team_color;
share|improve this answer