Render to texture?
« on: 23 May 2014, 13:12:14 »
Hi,

Is it possible to render a tgui::Gui into a sf::RenderTexture? I have been reading this post https://forum.tgui.eu/index.php/topic,119.0.html, but that code seems to target version 0.5 of tgui.

Reading up on the docs, it seems tgui:Gui has a method

Code: [Select]
void setWindow (sf::RenderWindow &window)
If that were generalised to

Code: [Select]
void setWindow (sf::RenderTarget &target)
then one could easily render into a texture, but there doesn't seem to be such an option.

Could anyone shed some light on this? Thanks.

*

texus

  • *****
  • 1161
    • View Profile
    • Texus's Blog
Re: Render to texture?
« Reply #1 on: 23 May 2014, 13:46:49 »
I'm afraid that it isn't possible.
That topic was about the fact that his render texure didn't display correctly anymore after using tgui, which was caused by badly linking the library. So you won't find much interesting in that topic.

Your generalisation will also not be possible due to the way the window is internally used (access to its view and the mapPixelToCoords function).

But depending on what you are trying to do, there are alternatives. If you only want to draw to a render texture in order to only use the gui on part of the screen, then you would be better of with setting a view for the gui.

So what is it that you are trying to accomplish exactly by rendering the gui to a render texture?

Re: Render to texture?
« Reply #2 on: 23 May 2014, 14:00:28 »
My goal is to apply some transformation to the resulting image, such as embedding the gui onto some 3D object. From what I'm seeing, I can always use a sf::Texture and update(the RenderWindow) to retrieve the result, but I suppose that's going to be slower.
« Last Edit: 23 May 2014, 14:17:37 by Jeanne-Kamikaze »

*

texus

  • *****
  • 1161
    • View Profile
    • Texus's Blog
Re: Render to texture?
« Reply #3 on: 23 May 2014, 14:08:57 »
I looked into it in more detail and it seems that I made a mistake in my previous post.
Your generalisation will work. I though the view was something from sf::Window, but apparently not.

I've made the change on github, so if you download and compile the latest code in the v0.6 branch then you will be able to render to a RenderTarget.

Re: Render to texture?
« Reply #4 on: 23 May 2014, 14:17:10 »
Fantastic, thanks. Will check it out now.

Re: Render to texture?
« Reply #5 on: 25 June 2014, 14:03:56 »
I forgot to mention that the current state of the library now is a bit weird because you have a method called setWindow that takes a RenderWindow or RenderTarget through overloading. Perhaps you might consider getting rid of setWindow / getWindow and have just two methods, setRenderTarget and getRenderTarget, that take and return a RenderTarget, respectively.

*

texus

  • *****
  • 1161
    • View Profile
    • Texus's Blog
Re: Render to texture?
« Reply #6 on: 25 June 2014, 14:13:22 »
Right after I made the change, I noticed a problem with the render texture. In order to use the system clipboard on windows, I need the window handle. Currently the system clipboard simply doesn't get used when you pass a RenderTarget instead of a RenderWindow. So I can't get rid of the setWindow function, unless I would add a new setWindowHandle function and force people to call it just to get the system clipboard working on windows.

I hope that sfml will at some point add a clipboard, so that I can remove that code and make the change you suggest.

Re: Render to texture?
« Reply #7 on: 25 June 2014, 14:38:14 »
Ah, your solution seems reasonable enough in that case.