sf::Color (http://www.sfml-dev.org/documentation/2.0/classsf_1_1Color.php) can be constructed from rgb values, therefore it's possible to manipulate the colors via arithmetic.
Alternatively, a simple function like this would do:
sf::Color getColor(const Team& team){
if (team==Team1) return sf::Color::Red;
if (team==Team2) return sf::Color::Blue;
etc
}
Sprite::setColor will not achieve the same effect as a palette would. But fortunately, SFML supports shaders, and the palette "effect" could be achieved with shader.
On the OpenGL website : http://www.opengl.org/wiki/Common_Mistakes#Paletted_textures
//Fragment shader
#version 110
uniform sampler2D ColorTable; //256 x 1 pixels
uniform sampler2D MyIndexTexture;
varying vec2 TexCoord0;
void main()
{
//What color do we want to index?
vec4 myindex = texture2D(MyIndexTexture, TexCoord0);
//Do a dependency texture read
vec4 texel = texture2D(ColorTable, myindex.xy);
gl_FragColor = texel; //Output the color
}
So you need to create an indexed texture and a palette texture.
Though I 'm not certain what exactly is it that SDL palette does, I could see manipulating the pixels of a sf::Image instead:
sf::Image trikeImage;
trikeImage.loadFromFile("graphics/Unit_Trike.bmp");
sf::Vector2u trikeSize = trikeImage.getSize();
sf::Image trikeGreen;
trikeGreen.create(trikeSize.x, trikeSize.y);
sf::Image trikeBlue;
trikeBlue.create(trikeSize.x, trikeSize.y);
for (int i=0; i<trikeSize.x; ++i){
for (int j=0; j<trikeSize.y; ++j){
sf::Color pixelColor = trikeImage.getPixel(i,j);
sf::Color bluePixel(pixelColor);
sf::Color greenPixel(pixelColor);
if ((pixelColor == sf::Color(125,0,0))
||(pixelColor == sf::Color(214,0,0))
||(pixelColor == sf::Color(60,0,0))
||(pixelColor == sf::Color(89,0,0))
||(pixelColor == sf::Color(153,0,0))
||(pixelColor == sf::Color(182,0,0))
)
{
greenPixel = sf::Color(0,pixelColor.g+pixelColor.r,pixelColor.b, pixelColor.a);
bluePixel = sf::Color(0,pixelColor.g,pixelColor.b+pixelColor.r, pixelColor.a);
}
trikeGreen.setPixel(i,j,greenPixel);
trikeBlue.setPixel(i,j,bluePixel);
}
}
(http://kojirion.github.io/images/hues.png)