IMG_LoadTextureTyped_IO(3)

πŸŽ€ IMG_LoadTextureTyped_IO(3) πŸŽ€

okay so we're on the SDL_image3 FUNCTIONS page, bestie, and this one is literally about turning image data from an SDL data source into a texture. slay. πŸ’…

πŸ’– NAME πŸ’–

IMG_LoadTextureTyped_IO β€” load an image from an SDL data source into a texture.

✨ SYNOPSIS ✨

#include <SDL3_image/SDL_image.h>

SDL_Texture * IMG_LoadTextureTyped_IO(SDL_Renderer *renderer, SDL_IOStream *src, bool closeio, const char *type);

πŸ¦‹ DESCRIPTION πŸ¦‹

An SDL_Texture represents an image in GPU memory, usable by SDL's 2D Render API. This can be significantly more efficient than using a CPU-bound SDL_Surface if you don't need to manipulate the image directly after loading it. it's giving "let the GPU cook" energy, fr fr. πŸ”₯

If the loaded image has transparency or a colorkey, a texture with an alpha channel will be created. Otherwise, SDL_image will attempt to create an SDL_Texture in the format that most reasonably represents the image data (but in many cases, this will just end up being 32-bit RGB or 32-bit RGBA). no cap, that's the vibe. 🌈

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. so like, don't stress about it still needing the stream after this call β€” it doesn't. 🫢

⚠️ bestie, pay attention to closeio: if it's true, the stream gets closed before returning even if things go sideways. iconic but also very much a "read the flag" moment. πŸ’€

Even though this function accepts a file type, SDL_image may still try other decoders that are capable of detecting file type from the contents of the image data, but may rely on the caller-provided type string for formats that it cannot autodetect. If type is NULL, SDL_image will rely solely on its ability to guess the format. iykyk. 🧚

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

There is also IMG_LoadTexture_IO(), which is equivalent to this function except that it will rely on SDL_image to determine what type of data it is loading, much like passing a NULL for type. that's the "let SDL_image figure it out" cousin. πŸ‘‘

If you would rather decode an image to an SDL_Surface (a buffer of pixels in CPU memory), call IMG_LoadTyped_IO() instead. different main character energy, same image-loading family. 🌸

When done with the returned texture, the app should dispose of it with a call to SDL_DestroyTexture(). please don't leave your textures lying around, bestie β€” clean up your room. πŸŽ€

🧸 FUNCTION PARAMETERS 🧸

  • renderer β€” the SDL_Renderer to use to create the texture.
  • src β€” an SDL_IOStream that data will be read from.
  • closeio β€” true to close/free the SDL_IOStream before returning, false to leave it open.
  • type β€” a filename extension that represent this data ("BMP", "GIF", "PNG", etc).

⭐ RETURN VALUE ⭐

Returns a new texture, or NULL on error. so if you get NULL, that's your cue to go check the error situation. 😭

🌟 AVAILABILITY 🌟

This function is available since SDL_image 3.0.0. she's been here a minute, periodt. πŸ’œ

πŸ‘€ SEE ALSO πŸ‘€


cute little sign-off time: this page's source/manual name is SDL_image, version SDL_image 3.4.4 β€” and the date isn't listed on this footer, so we're not inventing one, bestie. 🫢✨

πŸ“¦ where this page comes from