Hello, I'm having issues at the moment, because I am trying to get layers working in my map editor. So basically I have a layer for the next height level and one for the ground, these are basically just vectors of tile numbers. These then get drawn to their own render texture allowing me to split the rendering so that i can render characters and other objects in between. i.e so a character is in a doorway rather than on top of it, etc.
however for some reason the alpha from my top layer is being rendered as black and is hiding the ground layer. I don't have these issues when using one render texture, but i would like them split up for the above reasons as well as for versatility. Here is a minimal example that produces the annomally:
sf::RenderWindow window;
window.create(sf::VideoMode(400, 400), "test");
window.setFramerateLimit(60);
//initialise and load texture of tilesheet
sf::Texture tileset;
tileset.loadFromFile("graphics/tileSheet.png");
//create sprite that uses the tilesheet as its texture
sf::Sprite tileSprite(tileset);
//create 2 render textures to act as layers, one for the ground, one for a higher level
sf::RenderTexture tempTexture1;
sf::RenderTexture tempTexture2;
tempTexture1.create(400, 400);
tempTexture2.create(400, 400);
//create 2 sprites refering to the render textures
sf::Sprite tempSprite1(tempTexture1.getTexture());
sf::Sprite tempSprite2(tempTexture2.getTexture());
//set texture rects so that one is positioned where tiles are in the tilesheet
//the second is positioned where empty alpha tiles are for test purposes
tempSprite1.setTextureRect(sf::IntRect(0, 0, 400, 400));
tempSprite2.setTextureRect(sf::IntRect(0, 200, 400, 400));
//set sprites location so the drawn layers will overlap
tempSprite1.setPosition(0, 0);
tempSprite2.setPosition(0, 0);
//draw the sections of the tilesheet to the two different render textures
tempTexture1.clear();
tempTexture1.draw(tileSprite);
tempTexture1.display();
tempTexture2.clear();
tempTexture2.draw(tileSprite);
tempTexture2.display();
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if(event.type == sf::Event::Closed)
window.close();
}
//draw the bottom layer and then the top
window.clear();
window.draw(tempSprite1);
window.draw(tempSprite2);
window.display();
}
just to clarify, the tilesheet is only half full of tiles, so the second render texture has blank transparent tiles rendered to it.
Any help would be appreciated, pulling hair out etc etc :/