Assuming you're rendering the minimap to a render texture you can use a shader:
Uniform sampler2d tex;
Const float radius = 0.5;
Const float centre = 0.5;
Void main
{
Vec2 UV = gl_texcoord[0].xy;
Vec4 colour = texture2d(TeX, UV);
Const float distance = distance(centre, UV);
If(distance > radius) colour.a = 0;
gl_fragcolor = colour;
}
Sounds good fallahn, but my experience with shader is nearly zero.
i tried to implement your snippet with (tried vertex and fragment)
sf::Shader shader;
// load only the vertex shader
if (!shader.loadFromFile("shader.vert", sf::Shader::Vertex))
{
std::cout << "errorshadder";
}
shader.setParameter("texture", sf::Shader::CurrentTexture);
and
/* MINIMAP */
sf::View testview(sf::FloatRect(0, 0, 120, 120));
testview.setViewport((sf::FloatRect(0.75, 0.1, 0.2, 0.2)));
testview.zoom(10);
testview.setCenter(MainPlayer.GetPlayerSprite().getPosition().x+16,MainPlayer.GetPlayerSprite().getPosition().y+16);
window.setView(testview);
window.draw(MainChunk->GetBgSprite(),&shader);
if(MainPlayer.GetPlayerDirection() == 1)
{
window.draw(MainChunk->GetMainSprite(),&shader);
window.draw(MainPlayer.GetPlayerSprite(),&shader);
}
else
{
window.draw(MainPlayer.GetPlayerSprite(),&shader);
window.draw(MainChunk->GetMainSprite(),&shader);
}
window.draw(circle);
window.draw(MainChunk->GetCollisionSprite(),&shader);
but i get a mass of compiling errors, i tried a few things and tried to set it up like in the tutorial but failed kinda hard x.X
(http://s1.directupload.net/images/131031/4k34h2xc.png)
// MINIMAP
RenderTexture.clear(sf::Color(0,0,0,0));
sf::CircleShape MinimapShape(50.F);
sf::View testview(sf::FloatRect(0, 0, 120, 120));
testview.setViewport((sf::FloatRect(0.75, 0.1, 0.2, 0.2)));
testview.zoom(10);
testview.setCenter(MainPlayer.GetPlayerSprite().getPosition().x+16,MainPlayer.GetPlayerSprite().getPosition().y+16);
RenderTexture.setView(testview);
RenderTexture.draw(MainChunk->GetBgSprite());
if(MainPlayer.GetPlayerDirection() == 1)
{
RenderTexture.draw(MainChunk->GetMainSprite());
RenderTexture.draw(MainPlayer.GetPlayerSprite());
}
else
{
RenderTexture.draw(MainPlayer.GetPlayerSprite());
RenderTexture.draw(MainChunk->GetMainSprite());
}
//RenderTexture.draw(circle);
RenderTexture.draw(MainChunk->GetCollisionSprite());
MinimapShape.setTexture(&RenderTexture.getTexture());
window.draw(MinimapShape);
window.display();
I did it like this but actually nothing happens, probably a mistake by me?