Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Problem understanding RenderTexture, SFML 2  (Read 5210 times)

0 Members and 1 Guest are viewing this topic.

93interactive

  • Newbie
  • *
  • Posts: 39
    • View Profile
    • http://93-interactive.com
Problem understanding RenderTexture, SFML 2
« 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Problem understanding RenderTexture, SFML 2
« Reply #1 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.
Laurent Gomila - SFML developer

93interactive

  • Newbie
  • *
  • Posts: 39
    • View Profile
    • http://93-interactive.com
Problem understanding RenderTexture, SFML 2
« Reply #2 on: October 23, 2011, 01:14:16 pm »
yes, that does the trick, thank you

 

anything