SDL_OpenCamera(3)
π SDL_OpenCamera(3) π
okay bestie, welcome to the SDL3 FUNCTIONS page for SDL_OpenCamera β yes, we're opening a video recording device (a "camera") πΈβ¨
β¨ NAME β¨
SDL_OpenCamera β open a video recording device (a "camera"). no cap, that's the whole job π
π¦ SYNOPSIS π¦
#include <SDL3/SDL_camera.h>
SDL_Camera * SDL_OpenCamera(SDL_CameraID instance_id, const SDL_CameraSpec *spec);
πΈ DESCRIPTION πΈ
so here's the tea β β you can open the device with any reasonable spec, and if the hardware can't directly support it, it will convert data seamlessly to the requested format. lowkey slay, but heads up: this might incur overhead, including scaling of image data. it's giving "we did it but we worked for it" π
if you would rather just accept whatever format the device offers, you can pass a NULL spec here and it will choose one for you (and you can use SDL_Surface's conversion/scaling functions directly if necessary). main character energy: let the device decide π«Ά
you can call SDL_GetCameraFormat() to get the actual data format if passing a NULL spec here. and if you wanna see the exact specs a device can support without conversion, that's SDL_GetCameraSupportedFormats() β¨
SDL will not attempt to emulate framerate. it will try to set the hardware to the rate closest to the requested speed, but it won't attempt to limit or duplicate frames artificially. so call SDL_GetCameraFormat() to see the actual framerate of the opened the device, and check your timestamps if this is crucial to your app! β±οΈ not me warning you twice, but like, do it π
π¨ IMPORTANT BESTIE π¨ note that the camera is not usable until the user approves its use! on some platforms, the operating system will prompt the user to permit access to the camera, and they can choose Yes or No at that point. until they do, the camera will not be usable. the app should either wait for anSDL_EVENT_CAMERA_DEVICE_APPROVED(orSDL_EVENT_CAMERA_DEVICE_DENIED) event, or pollSDL_GetCameraPermissionState()occasionally until it returns non-zero. on platforms that don't require explicit user approval (and perhaps in places where the user previously permitted access), the approval event might come immediately, but it might come seconds, minutes, or hours later! π like, hours. fr fr.
π FUNCTION PARAMETERS π
instance_idβ the camera device instance ID. πspecβ the desired format for data the device will provide. Can beNULL. π
β RETURN VALUE β
returns an SDL_Camera object, or NULL on failure π₯² β call SDL_GetError() for more information. (iykyk, always check the error.)
π§ THREAD SAFETY π§
it is safe to call this function from any thread. go off, multithreaded queen π
π AVAILABILITY π
this function is available since SDL 3.2.0 β¨
π SEE ALSO π
and that's the whole page, bestie!! π«Ά this lil' beauty comes to you from Simple Directmedia Layer, version SDL 3.4.18 β mwah, obsessed, periodt π ππ¦
π¦ where this page comes from
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms