Take a look at the
shader tutorial. The sprite coloring effect can easily be achieved with the following shader.
//main.cpp
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(640, 480), "ยค");
sf::Shader shader;
if (!shader.loadFromFile("fragment.frag", sf::Shader::Fragment)) {/*error*/}
sf::Texture texture;
texture.loadFromFile("sprite.png");
sf::Sprite sprite;
sprite.setTexture(texture);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed) {
window.close();
}
if (event.type == sf::Event::KeyReleased) {
if (event.key.code == sf::Keyboard::Escape) {
window.close ();
}
}
}
shader.setParameter("texture", sf::Shader::CurrentTexture);
shader.setParameter("color", sf::Color::Green);
window.clear();
window.draw(sprite, &shader);
window.display();
}
return 0;
}
//fragment.frag
uniform sampler2D texture;
uniform vec4 color;
void main()
{
vec4 pixel = vec4(color.rgb, texture2D(texture, gl_TexCoord[0].xy).a);
gl_FragColor = gl_Color * pixel;
}
If you want to draw a border around your sprite (I'm not sure that's what your asking), there was a thread a few weeks ago about
how to draw a text with an outline (border).
Right part is what the above code looks like, left part is what it looks like if you draw 8 additional sprites moved with (0, 1) (1, 1) etc. offsets and a black color passed to the shader.