SFML community forums

Help => Graphics => Topic started by: Zyl on January 24, 2014, 06:52:22 pm

Title: Initialize sf::Texture with a GL texture?
Post by: Zyl on January 24, 2014, 06:52:22 pm
Hello.

Is it possible to init an sf::Texture (http://www.sfml-dev.org/documentation/2.0/classsf_1_1Texture.php) with a GL texture? I have an advanced OpenGL project and want to add a simple menu over a transparent black rectangle using SFML (mostly because the text rendering functionality spares me a lot of work), so I need to render to texture in my final rendering pass and make an sf::RectangleShape (http://www.sfml-dev.org/documentation/2.0/classsf_1_1RectangleShape.php) which uses part of that texture for the effect of drawing over it transparently. However, all functions on sf::Texture (http://www.sfml-dev.org/documentation/2.0/classsf_1_1Texture.php) want to load from file, stream or memory, instead of taking a ready GL texture name/handle.

Is there a way to achieve what I want? Thanks!
Title: Re: Initialize sf::Texture with a GL texture?
Post by: wintertime on January 24, 2014, 10:08:22 pm
It reads as if you are thinking about that backwards. You should not copy the OpenGL graphics you just had drawn onto the backbuffer into the sf::Texture to modify it.
Just draw everything you want with OpenGL, then draw the GUI over it using SFML-Graphics (may need some calls to setActive and ResetGLState which is explained in the tutorial about using SFML with OpenGL).
Alternatively use a RenderTexture and when drawing the GUI clear it to transparent black and draw all GUI elements and call display on it (dont forget to reactivate the Window after that). Then on each frame after drawing the things you use OpenGL for, get the Texture from the RenderTexture and draw that over it (and if using OpenGL activate blending).
Title: Re: Initialize sf::Texture with a GL texture?
Post by: Zyl on January 25, 2014, 12:56:43 am
Quote
blending

Didn't know GL could do this haha. It works perfectly. Thanks!