Search code examples
c++windowsdl-2renderer

using SDL_Texture* on several SDL_Renderers*


I'm trying to use the same SDL_Texture* on two separate SDL_Renderer*, but apparently SDL_Texture seems to be "tied" to a SDL_Renderer*.
Is there a way to make the second renderer able to use the texture created through SDL_CreateTextureFromSurface using the first renderer? If i try doing so by just copying the SDL_Texture* pointer and using SDL_RenderCopy with the second renderer, the screen stays black.

If more details are needed:
I'm using the SDL2 library in Virtual Studio. I have two separate SDL_Window's, each with one SDL_Renderer. The window containing the first renderer is permanently existen through the whole program, while the second window is only created, when needed and destroyed shortly after.


Solution

  • Not sure, if it's the most straightforward way, but you could copy your texture to an SDL_Surface, and then at the other end use SDL_CreateTextureFromSurface.