SFML community forums

Help => Graphics => Topic started by: 93interactive on October 23, 2011, 09:53:19 am

Title: Problem understanding RenderTexture, SFML 2
Post by: 93interactive on October 23, 2011, 09:53:19 am
Hi,

i having a weird situation that i do not understand, maybe someone could explain me what happens and if there is a way to prevent this.

I have a level, built from a tile map, that i render into a RenderTexture (the whole map at once). Although drawing only the visible portion of the tile map would be faster, i need this to be able to modify the level by for example adding blood splatter onto the tiles.

From that render texture, i build a sprite, and that i do render.

Now everything works fine, until i do load any other texture after setting up the RenderTexture object. Once i load any texture object, the RenderTexture seems to get replaced with that texture.

So in code speaking (not the actual code, just to make clear what i am talking about):

Code: [Select]

RenderTexture t;
Sprite s;
Texture otherTex;
Sprite otherSprite;

void init() {
   otherTex.LoadFromFile("sprite.png");
   otherSprite.SetTexture(otherTex);
   RenderTexture t;
   t.Create(800, 600);
   DrawMap(t);
   t.Display();
   s.SetTexture(t.GetTexture());
}

void draw() {
   window.Clear();
   window.Draw(s);
}


does work, while...:

Code: [Select]

void init() {
   RenderTexture t;
   t.Create(800, 600);
   DrawMap(t);
   t.Display();
   s.SetTexture(t.GetTexture());

   otherTex.LoadFromFile("sprite.png");
   otherSprite.SetTexture(otherTex);
}

void draw() {
   window.Clear();
   window.Draw(s);
}


...does draw a large scaled image of sprite.png

Why is this happening?
Title: Problem understanding RenderTexture, SFML 2
Post by: Laurent on October 23, 2011, 10:19:23 am
It's probably a bug in SFML. Try to comment line 236 of src/SFML/Graphics/Renderer.cpp and recompile SFML.
Title: Problem understanding RenderTexture, SFML 2
Post by: 93interactive on October 23, 2011, 01:14:16 pm
yes, that does the trick, thank you