Drawing a Texture into another Texture

Hi everyone :).
I’m currently developing a game that I started 3 years ago. At that time, I was using SDL 1.2.
But I recently discovered that SDL 2.0 came out, and now I want to move my game from SDL 1.2 to SDL 2.0.

So I started to replace all SDL_Surface* into SDL_Texture*.
But now I have a problem : I have a method in my “Player” class which draws the character. The character is made of several pictures : The body, the hairs, the clothes (and eventually a hat). I used to use a temporary SDL_Surface and then blit all these elements into this surface, and then use it to draw it directly to the screen. I did that because when a character teleports (change map for exemple) it fades. And I want all parts of the character to fade at the same time and not each part separated.

So my question is that : It is possible to draw a Texture into another Texture (just like a Surface) ?
I believe it is not possible, but in that case what are the choices left for me ? Because I want to get rid of my Surfaces and transform them into Textures.

Thanks in advance for every answer I’ll get :).
Good evening.

Grade wrote:

Hi everyone :).
I’m currently developing a game that I started 3 years ago. At that time, I was using SDL 1.2.
But I recently discovered that SDL 2.0 came out, and now I want to move my game from SDL 1.2 to SDL 2.0.

So I started to replace all SDL_Surface* into SDL_Texture*.
But now I have a problem : I have a method in my “Player” class which draws the character. The character is made of several pictures : The body, the hairs, the clothes (and eventually a hat). I used to use a temporary SDL_Surface and then blit all these elements into this surface, and then use it to draw it directly to the screen. I did that because when a character teleports (change map for exemple) it fades. And I want all parts of the character to fade at the same time and not each part separated.

So my question is that : It is possible to draw a Texture into another Texture (just like a Surface) ?
I believe it is not possible, but in that case what are the choices left for me ? Because I want to get rid of my Surfaces and transform them into Textures.

Thanks in advance for every answer I’ll get :).
Good evening.

Yes, it is possible. First - when calling SDL_CreateRenderer() to create the renderer, you’ll need to make sure the SDL_RENDERER_TARGETTEXTURE bit is set in the flags (OR’ed with SDL_RENDERER_ACCELERATED or whatever). Second, you’ll need to create a texture with the access parameter set to SDL_TEXTUREACCESS_TARGET. Then all you have to do is call SDL_SetRenderTarget(), specifying your target texture, and all SDL_RenderCopy() calls from that point will render to that texture instead of the screen. When you’ve finished your character spritesheet, call SDL_SetRenderTarget() again with NULL for the target to point it back to the screen, and continue on as usual.

1 Like

Yes it’s possible. You can set the render target to an other texture and
then do a render copy. We’ve already answered this question before.On Fri, Nov 15, 2013 at 9:57 PM, Grade wrote:

Hi everyone [image: Smile].
I’m currently developing a game that I started 3 years ago. At that time,
I was using SDL 1.2.
But I recently discovered that SDL 2.0 came out, and now I want to move my
game from SDL 1.2 to SDL 2.0.

So I started to replace all SDL_Surface* into SDL_Texture*.
But now I have a problem : I have a method in my “Player” class which
draws the character. The character is made of several pictures : The body,
the hairs, the clothes (and eventually a hat). I used to use a temporary
SDL_Surface and then blit all these elements into this surface, and then
use it to draw it directly to the screen. I did that because when a
character teleports (change map for exemple) it fades. And I want all parts
of the character to fade at the same time and not each part separated.

So my question is that : It is possible to draw a Texture into another
Texture (just like a Surface) ?
I believe it is not possible, but in that case what are the choices left
for me ? Because I want to get rid of my Surfaces and transform them into
Textures.

Thanks in advance for every answer I’ll get [image: Smile].
Good evening.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Thanks for the answer guys, it works perfectly :slight_smile: