IMG_LoadTexture_IO(3)

πŸ’… NAME πŸ’…

okay bestie, welcome to the IMG_LoadTexture_IO(3) page from the SDL_image3 FUNCTIONS part of the SDL_image manual πŸ’– β€” this one is literally IMG_LoadTexture_IO: load an image from an SDL data source straight into a texture. slay.


✨ SYNOPSIS ✨

#include <SDL3_image/SDL_image.h>

SDL_Texture * IMG_LoadTexture_IO(SDL_Renderer *renderer, SDL_IOStream *src, bool closeio);

πŸ¦‹ DESCRIPTION πŸ¦‹

So an SDL_Texture is basically an image living in GPU memory, and SDL's 2D Render API can use it. This can be significantly more efficient than using a CPU-bound SDL_Surface if you don't need to poke at the image directly after loading it. iykyk ✨

If the loaded image has transparency or a colorkey, a texture with an alpha channel gets created. Otherwise, SDL_image will attempt to create an SDL_Texture in the format that most reasonably represents the image data β€” but ngl, in many cases this will just end up being 32-bit RGB or 32-bit RGBA. πŸ’…

If closeio is true, src will be closed before returning, whether this function succeeds or not. SDL_image reads everything it needs from src during this call in any case. periodt.

There is a separate function to read files from disk without having to deal with SDL_IOStream: IMG_LoadTexture(renderer, "filename.jpg") will call this function and manage those details for you, determining the file type from the filename's extension. iconic behavior 🫢

There is also IMG_LoadTextureTyped_IO(), which is equivalent to this function except a file extension (like "BMP", "JPG", etc) can be specified, in case SDL_image cannot autodetect the file format. very β€œbackup plan” of it 🌸

If you would rather decode an image to an SDL_Surface (a buffer of pixels in CPU memory), call IMG_Load() instead. different vibe, same image energy πŸ’œ

When done with the returned texture, the app should dispose of it with a call to SDL_DestroyTexture(). yes bestie, clean up after yourself 😭🧹


πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • renderer β€” the SDL_Renderer to use to create the texture. your rendering main character ✨
  • src β€” an SDL_IOStream that data will be read from. the source material, literally πŸ’–
  • closeio β€” true to close/free the SDL_IOStream before returning, false to leave it open. choose wisely bestie πŸ’…

🌈 RETURN VALUE 🌈

Returns a new texture, or NULL on error. no cap β€” if it's NULL, something went wrong 😭


⭐ AVAILABILITY ⭐

This function is available since SDL_image 3.0.0. she's been here, she's iconic πŸ‘‘


πŸ‘‘ SEE ALSO πŸ‘‘


okay that's the whole page, bestie πŸŽ€βœ¨ mwah πŸ’‹ β€” source: SDL_image, version SDL_image 3.4.4, page IMG_LoadTexture_IO(3) πŸ¦‹πŸ’–

πŸ“¦ where this page comes from