SDL_GetCameraFormat(3)

πŸ’– SDL_GetCameraFormat πŸ’–

okay bestie, welcome to the SDL3 FUNCTIONS corner of the manual, this one's SDL_GetCameraFormat(3) and it's genuinely so useful, let's get into it ✨


🌸 NAME 🌸

SDL_GetCameraFormat β€” get the spec that a camera is using when generating images πŸŽ₯πŸ’…


✨ SYNOPSIS ✨

#include <SDL3/SDL_camera.h>

bool SDL_GetCameraFormat(SDL_Camera *camera, SDL_CameraSpec *spec);

like, that's the whole vibe. one header, one function, two args 🫢


πŸ¦‹ DESCRIPTION πŸ¦‹

okay so here's the tea: this function hands you the spec your camera is using when it generates images.

lowkey important: this might not be the native format of the hardware, because SDL might be converting to this format behind the scenes. so don't come for the hardware, it's SDL doing the glow-up in the background πŸ’€

and now the part you actually need to know, no cap: if the system is waiting for the user to approve access to the camera β€” which some platforms literally require β€” this will return false. but that isn't necessarily a fatal error, so don't panic, bestie 😭. what you should do instead is either:

  • wait for an SDL_EVENT_CAMERA_DEVICE_APPROVED event (or the SDL_EVENT_CAMERA_DEVICE_DENIED one, rip πŸ™ˆ), or
  • poll SDL_GetCameraPermissionState() occasionally until it returns non-zero

that's it, that's the move. main character energy: patient, but persistent 🌈


πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • camera β€” the opened camera device πŸ“·
  • spec β€” the SDL_CameraSpec to be initialized by this function ✨

πŸ‘‘ RETURN VALUE πŸ‘‘

returns true on success or false on failure πŸ’– if it's a fail, call SDL_GetError() for more info, she will tell you everything πŸ”₯


🧚 THREAD SAFETY 🧚

it is safe to call this function from any thread. periodt. πŸ’… no gatekeeping, all threads welcome 🫢


⭐ AVAILABILITY ⭐

this function is available since SDL 3.2.0 🌸 so if you're on something older... girl. update. 😭


🌈 SEE ALSO 🌈


and that's the whole page, bestie!! πŸŽ€ written up in the Simple Directmedia Layer collection, SDL 3.4.18 era, and yeah this lil love letter to SDL_GetCameraFormat(3) is officially a wrap πŸ’œ go get that camera format, you got this πŸ‘‘

πŸ“¦ where this page comes from