[SDL2_Image]-Load PNG Directly Into SDL Texture?

[SDL2_Image]-Load PNG Directly Into SDL Texture?

Hi,

Is it possible to use SDL2_Image to load a PNG image directly into an SDL texture?
Or we have to load PNG into SDL surface 1st and then convert surface into a texture?
Thanks!------------------------
JeZ+Lee
JessePalser <AT> Gmail <DOT> com
16BitSoft®
Video Game Design Studio
www.16BitSoft.com

Or we have to load PNG into SDL surface 1st and then convert surface
into a texture?

Yep, SDL_CreateTextureFromSurface(), then free the surface.

You could also just SDL_CreateTexture() with a memory buffer of pixels,
but the overhead of moving from a Surface to a Texture isn’t much
bigger, and it’s better about handling format conversions, etc.

–ryan.

Actually, in SDL2, SDL_Image got a few new API functions:

/* Load an image directly into a render texture.
?*/
extern DECLSPEC SDL_Texture * SDLCALL IMG_LoadTexture(SDL_Renderer *renderer, const char *file);
extern DECLSPEC SDL_Texture * SDLCALL IMG_LoadTexture_RW(SDL_Renderer *renderer, SDL_RWops *src, int freesrc);
extern DECLSPEC SDL_Texture * SDLCALL IMG_LoadTextureTyped_RW(SDL_Renderer *renderer, SDL_RWops *src, int freesrc, const char *type);________________________________
From: Ryan C. Gordon
To: sdl at lists.libsdl.org
Sent: Monday, August 12, 2013 9:11 PM
Subject: Re: [SDL] [SDL2_Image]-Load PNG Directly Into SDL Texture?

Or we have to load PNG into SDL surface 1st and then convert surface
into a texture?

Yep, SDL_CreateTextureFromSurface(), then free the surface.

You could also just SDL_CreateTexture() with a memory buffer of pixels,
but the overhead of moving from a Surface to a Texture isn’t much
bigger, and it’s better about handling format conversions, etc.

–ryan.


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

Whoops, yes, that’s correct, I forgot about that.

(My advice was good if you aren’t using SDL_image though!!) :slight_smile:

–ryan.On 08/13/2013 12:42 AM, Mason Wheeler wrote:

Actually, in SDL2, SDL_Image got a few new API functions: