White sprite then choose colour

I was looking at the sprites that come with ‘Project Zomboid’, and reading a news update about how they at first had problems having to bind so many textures (in openGL) so eventually made a sprite atlas (I think thats the correct term). Just one character has a huge number of frames, and I was wondering, can you not simply provide a white styled sprite outfit, then use colours (in the case for opengl, glColor4f()) to colour them? This is what I was intending on doing, or have I missed some concept that makes this a bad idea?

How would you color each section of the sprite?

If it was done in grey and white, for shape and shading, would then changing the colour not alter the bits appropriately? For this I mean clothing for example, so base human sprites then coloured top/bottoms

Yes, but a sprite usually has many parts of different colors, how would you color each one?

I’d seperate each part into a different sprite, which in their case would still be far fewer sprites. Also for me, and them (thus far) for example, their tops are all the same shape, just different shades of one colour. Everything that isnt supposed to be coloured obviously would be alpha so uneffected (I believe?)

If you split everything up then yes that would work. However I don’t think it was just the colouring that the Zomboid guys were having problems with - it was the combinatorial explosion of lots of different animations at different angles while holding different weapons and different colours. When there’s that many combinations it starts to make much more sense to do things in 3d (even if you just render it out into sprites and don’t use the 3d models directly).

If you just want to recolour things you can also go old school and do palette swapping tricks (although you might have to emulate that in a shader).

grrr. I need to use game libraries so i can understand these questions

The complexity when recoloring sprites really depends on how much color variation goes into it.

If the color variation is simple (For example, each section only has dark, normal and bright colors), you can just draw and color the sprite normally, and then programatically recolor each section (as you know the base colors beforehand).

For example, let’s say you want to recolor your Space Marine’s armor and pants, so you draw the sprite normally, paint the armor green (RGB: #00FF00) and the pants blue (RGB: #0000FF), with the three color intensities being percentages (Dark 25%, Normal 75%, Bright 100%). Of course you have to make sure the rest of the sprite does not use any of these values

Now, when the player decides the Space Marine desperately needs a pair of hot pink pants (RGB: #FEBFEF), your program needs to look for all the Dark Blue, Normal Blue and Light Blue pixels, and replace them with the corresponding Hot Pink values.

Alternatively, use indexed color, and alter the palette in game. Or maybe save your sprite images with two layers: Color and Brightness (Grayscale), then alter the colors and multiply by the brightness layer.

There are plenty of ways to handle this programatically. One recommendation I’d make, though, is that, unless the colors need to change during gameplay (In which case palette swapping might be the way to go), make sure to pre-generate the recolored sprites during the loading phase on a per entity basis, for performance’s sake.