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

Author Topic: sf::RenderTexture as a normal texture?  (Read 2375 times)

0 Members and 1 Guest are viewing this topic.

JunkerKun

  • Newbie
  • *
  • Posts: 35
    • View Profile
sf::RenderTexture as a normal texture?
« on: July 28, 2013, 05:20:29 pm »
Hello.

Is it a good idea to keep RenderTexture in a memory and use it as a normal Texture after everything needed had been drawn to it?

I mean, I need to create a sprite made of two other sprites. To not just draw two sprites on top of each other (I need the sprite to be half-transparent and not being able to see a bottom sprite throught the top one) I want to render them both in a RenderTexture and use it as a Texture.

Should I keep the RenderTexture or just render sprites to it in a real time? I don't think the second is a good idea since it may be a lot of sprites like that on the screen.

Is there any other way to do that?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: sf::RenderTexture as a normal texture?
« Reply #1 on: July 28, 2013, 07:14:10 pm »
From what I understand on what's going on in the background, it's totally okay to keep the RenderTexture around and use its texture. In an abstract way you can look at Texture and RenderTexture as the same thing, with the difference that the RenderTexture provides functions to change itself on the GPU memory.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: sf::RenderTexture as a normal texture?
« Reply #2 on: July 28, 2013, 07:25:42 pm »
However, if you don't change the render texture anymore, I recommend to store a separate texture.

sf::RenderTexture is a relatively expensive resource, since it uses an OpenGL texture, a framebuffer object (and with the current implementation even an own context if I remember correctly). Thus, for storage only you should definitely prefer sf::Texture.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

JunkerKun

  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: sf::RenderTexture as a normal texture?
« Reply #3 on: July 28, 2013, 09:40:03 pm »
Okay then, I'll use sf::Texture.
Thanks guys!

ahnonay

  • Guest
Re: sf::RenderTexture as a normal texture?
« Reply #4 on: July 28, 2013, 09:41:54 pm »
You would have to use sf::RenderTexture::getTexture(), which only returns a reference to the RenderTexture's internal Texture. So to retain the Texture after the RenderTexture has been destroyed, you must make a copy of it, which is a rather slow operation.
So I think you might as well just keep your RenderTexture in memory.

JunkerKun

  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: sf::RenderTexture as a normal texture?
« Reply #5 on: August 02, 2013, 09:15:37 pm »
You would have to use sf::RenderTexture::getTexture(), which only returns a reference to the RenderTexture's internal Texture. So to retain the Texture after the RenderTexture has been destroyed, you must make a copy of it, which is a rather slow operation.
So I think you might as well just keep your RenderTexture in memory.

I need to copy the texture only when loading actually. But thanks for the advice anyway.