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

Author Topic: Initialize sf::Texture with a GL texture?  (Read 2304 times)

0 Members and 1 Guest are viewing this topic.

Zyl

  • Newbie
  • *
  • Posts: 12
    • View Profile
Initialize sf::Texture with a GL texture?
« on: January 24, 2014, 06:52:22 pm »
Hello.

Is it possible to init an sf::Texture 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 which uses part of that texture for the effect of drawing over it transparently. However, all functions on sf::Texture 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!

wintertime

  • Sr. Member
  • ****
  • Posts: 255
    • View Profile
Re: Initialize sf::Texture with a GL texture?
« Reply #1 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).

Zyl

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Initialize sf::Texture with a GL texture?
« Reply #2 on: January 25, 2014, 12:56:43 am »
Quote
blending

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