Best method to create surfaces/textures

Just wondering, did I ask a silly question above? It’s had a lot of views but no answers yet …

I do have a tendency to ask silly questions - so it’s quite likely

… but do other people think this was an odd question?

gladrags wrote:

I am using SDL 2.0.

I have several pngs that I want to place side by side on screen, but I would like to create one single texture, or surface, consisting of the png image data, placed side by side.

What is the best method of doing this?

I am currently doing the following:

  1. create an RGB surface of a specified size
  2. load in all the png’s as surfaces
  3. blit these surfaces to my newly created RGB surface, in the right position.
  4. convert my custom RGB surface to a texture.
  5. render that to the window.

This works fine - but is it the best way? Should i create a texture, and load the png’s as textures and then render them to my specially made texture?
Is that even possible?

Yeah, that’s how one should do this. Blit everything in a temporary surface, convert it to texture and then render the texture. Just make sure that the surface size is enough to hold everything.

And, NO, rendering a texture on a texture is not supported.------------------------
C is the God’s Programming Language

2013/7/21, neoaggelos :

And, NO, rendering a texture on a texture is not supported.

Wait what, wouldn’t that render SDL_SetRenderTarget pointless?

Message-ID: <1374409145.m2f.38161 at forums.libsdl.org>
Content-Type: text/plain; charset=“iso-8859-1”

Just wondering, did I ask a silly question above? It’s had a lot of views
but no answers yet …

Views? Out of curiosity, are you using the forum? Most of the actual
activity seems to be on the mailinglist, and while the mailinglist and
the forum are automatically coordinated with each other, every once in
a while there does seem to be some bug in the system.> Date: Sun, 21 Jul 2013 05:19:05 -0700

Date: Sun, 21 Jul 2013 20:13:35 -0300
From: Sik the hedgehog <sik.the.hedgehog at gmail.com>
To: sdl at lists.libsdl.org
Subject: Re: [SDL] best method to create surfaces/textures
Message-ID:
<CAEyBR+UGAnw4yQD5dFRPXvbfXeJy+r84obE2PGWDhOuo0bNj+g at mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

2013/7/21, neoaggelos :

And, NO, rendering a texture on a texture is not supported.

Wait what, wouldn’t that render SDL_SetRenderTarget pointless?

Yes, which makes me wonder what neo is basing that statement on.
Perhaps the intended meaning was “you can only render to renderers,
not to windows or textures”?

Views? Out of curiosity, are you using the forum? Most of the actual
activity seems to be on the mailinglist, and while the mailinglist and
the forum are automatically coordinated with each other, every once in
a while there does seem to be some bug in the system.

Ah I see. The “views” number was probably that bug then - I’m using the forum rather than the mailing list.

Yes, which makes me wonder what neo is basing that statement on.
Perhaps the intended meaning was “you can only render to renderers,
not to windows or textures”?

So does this mean that I can perform my steps 1 to 3, that I outlined originally, but create a temporary texture rather than a surface, and blit textures to it ( rather than surfaces ) - and then there is no need to do any conversion, and I can just pass that texture directly to the renderer for blitting?

I was originally doing 1 to 3 with surfaces and then converting to a texture and then passing that texture to the renderer. But I had issues with black colour appearing on my PNGs where they should be transparent. I tried the suggestions on this forum for that (SDL_SurfaceSetBlendMode() ) but they didn’t work.

Loading my PNGs as textures gets rid of black problem, so ideally I’d like to be able to blit PNG textures to a temporary texture (i.e. steps 1 to 3 but with textures).

But now I’m confused … should I use SDL_SetRenderTarget() with my special temporary texture?

It’s a bit late, but the weekend’s finally here for me.> Date: Tue, 23 Jul 2013 04:02:47 -0700

From: “gladrags”
To: sdl at lists.libsdl.org
Subject: Re: [SDL] best method to create surfaces/textures
Message-ID: <1374577366.m2f.38197 at forums.libsdl.org>
Content-Type: text/plain; charset=“iso-8859-1”

Yes, which makes me wonder what neo is basing that statement on.
Perhaps the intended meaning was “you can only render to renderers,
not to windows or textures”?

So does this mean that I can perform my steps 1 to 3, that I outlined
originally, but create a temporary texture rather than a surface, and blit
textures to it ( rather than surfaces ) - and then there is no need to do
any conversion, and I can just pass that texture directly to the renderer
for blitting?

I was originally doing 1 to 3 with surfaces and then converting to a texture
and then passing that texture to the renderer. But I had issues with black
colour appearing on my PNGs where they should be transparent. I tried the
suggestions on this forum for that (SDL_SurfaceSetBlendMode() ) but they
didn’t work.

Loading my PNGs as textures gets rid of black problem, so ideally I’d like
to be able to blit PNG textures to a temporary texture (i.e. steps 1 to 3
but with textures).

But now I’m confused … should I use SDL_SetRenderTarget() with my special
temporary texture?

Give it a try.

You care about SDL_RENDERER_TARGETTEXTURE for the renderer, and for
the textures you care about SDL_TEXTUREACCESS_TARGET. Also, you can
use streaming textures if you don’t want to render individual images
more than once, though I’m not certain if there would be a worthwhile
speed difference. I haven’t checked to make certain that there’s an
actual implementation behind everything (and there doesn’t seem to be
a mention of it in the wiki yet), but SDL_RenderTargetSupported is a
function to check if you use a render target.

Alternatively, you might experiment with SDL_LockTexture (warning: not
if you’re blitting images on top of each other).