mirror of
https://github.com/thunderbrewhq/thunderbrew
synced 2025-12-12 03:02:30 +00:00
chore(build): use SDL3
This commit is contained in:
parent
9d04a35d87
commit
b3c0734a9e
3286 changed files with 866354 additions and 554996 deletions
1
vendor/sdl-3.2.10/examples/camera/01-read-and-draw/README.txt
vendored
Normal file
1
vendor/sdl-3.2.10/examples/camera/01-read-and-draw/README.txt
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
This reads from a webcam and draws frames of video to the screen.
|
||||
BIN
vendor/sdl-3.2.10/examples/camera/01-read-and-draw/onmouseover.webp
vendored
Normal file
BIN
vendor/sdl-3.2.10/examples/camera/01-read-and-draw/onmouseover.webp
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 339 KiB |
113
vendor/sdl-3.2.10/examples/camera/01-read-and-draw/read-and-draw.c
vendored
Normal file
113
vendor/sdl-3.2.10/examples/camera/01-read-and-draw/read-and-draw.c
vendored
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
/*
|
||||
* This example code reads frames from a camera and draws it to the screen.
|
||||
*
|
||||
* This is a very simple approach that is often Good Enough. You can get
|
||||
* fancier with this: multiple cameras, front/back facing cameras on phones,
|
||||
* color spaces, choosing formats and framerates...this just requests
|
||||
* _anything_ and goes with what it is handed.
|
||||
*
|
||||
* This code is public domain. Feel free to use it for any purpose!
|
||||
*/
|
||||
|
||||
#define SDL_MAIN_USE_CALLBACKS 1 /* use the callbacks instead of main() */
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_main.h>
|
||||
|
||||
/* We will use this renderer to draw into this window every frame. */
|
||||
static SDL_Window *window = NULL;
|
||||
static SDL_Renderer *renderer = NULL;
|
||||
static SDL_Camera *camera = NULL;
|
||||
static SDL_Texture *texture = NULL;
|
||||
|
||||
|
||||
/* This function runs once at startup. */
|
||||
SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
{
|
||||
SDL_CameraID *devices = NULL;
|
||||
int devcount = 0;
|
||||
|
||||
SDL_SetAppMetadata("Example Camera Read and Draw", "1.0", "com.example.camera-read-and-draw");
|
||||
|
||||
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_CAMERA)) {
|
||||
SDL_Log("Couldn't initialize SDL: %s", SDL_GetError());
|
||||
return SDL_APP_FAILURE;
|
||||
}
|
||||
|
||||
if (!SDL_CreateWindowAndRenderer("examples/camera/read-and-draw", 640, 480, 0, &window, &renderer)) {
|
||||
SDL_Log("Couldn't create window/renderer: %s", SDL_GetError());
|
||||
return SDL_APP_FAILURE;
|
||||
}
|
||||
|
||||
devices = SDL_GetCameras(&devcount);
|
||||
if (devices == NULL) {
|
||||
SDL_Log("Couldn't enumerate camera devices: %s", SDL_GetError());
|
||||
return SDL_APP_FAILURE;
|
||||
} else if (devcount == 0) {
|
||||
SDL_Log("Couldn't find any camera devices! Please connect a camera and try again.");
|
||||
return SDL_APP_FAILURE;
|
||||
}
|
||||
|
||||
camera = SDL_OpenCamera(devices[0], NULL); // just take the first thing we see in any format it wants.
|
||||
SDL_free(devices);
|
||||
if (camera == NULL) {
|
||||
SDL_Log("Couldn't open camera: %s", SDL_GetError());
|
||||
return SDL_APP_FAILURE;
|
||||
}
|
||||
|
||||
return SDL_APP_CONTINUE; /* carry on with the program! */
|
||||
}
|
||||
|
||||
/* This function runs when a new event (mouse input, keypresses, etc) occurs. */
|
||||
SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event)
|
||||
{
|
||||
if (event->type == SDL_EVENT_QUIT) {
|
||||
return SDL_APP_SUCCESS; /* end the program, reporting success to the OS. */
|
||||
} else if (event->type == SDL_EVENT_CAMERA_DEVICE_APPROVED) {
|
||||
SDL_Log("Camera use approved by user!");
|
||||
} else if (event->type == SDL_EVENT_CAMERA_DEVICE_DENIED) {
|
||||
SDL_Log("Camera use denied by user!");
|
||||
return SDL_APP_FAILURE;
|
||||
}
|
||||
return SDL_APP_CONTINUE; /* carry on with the program! */
|
||||
}
|
||||
|
||||
/* This function runs once per frame, and is the heart of the program. */
|
||||
SDL_AppResult SDL_AppIterate(void *appstate)
|
||||
{
|
||||
Uint64 timestampNS = 0;
|
||||
SDL_Surface *frame = SDL_AcquireCameraFrame(camera, ×tampNS);
|
||||
|
||||
if (frame != NULL) {
|
||||
/* Some platforms (like Emscripten) don't know _what_ the camera offers
|
||||
until the user gives permission, so we build the texture and resize
|
||||
the window when we get a first frame from the camera. */
|
||||
if (!texture) {
|
||||
SDL_SetWindowSize(window, frame->w, frame->h); /* Resize the window to match */
|
||||
texture = SDL_CreateTexture(renderer, frame->format, SDL_TEXTUREACCESS_STREAMING, frame->w, frame->h);
|
||||
}
|
||||
|
||||
if (texture) {
|
||||
SDL_UpdateTexture(texture, NULL, frame->pixels, frame->pitch);
|
||||
}
|
||||
|
||||
SDL_ReleaseCameraFrame(camera, frame);
|
||||
}
|
||||
|
||||
SDL_SetRenderDrawColor(renderer, 0x99, 0x99, 0x99, SDL_ALPHA_OPAQUE);
|
||||
SDL_RenderClear(renderer);
|
||||
if (texture) { /* draw the latest camera frame, if available. */
|
||||
SDL_RenderTexture(renderer, texture, NULL, NULL);
|
||||
}
|
||||
SDL_RenderPresent(renderer);
|
||||
|
||||
return SDL_APP_CONTINUE; /* carry on with the program! */
|
||||
}
|
||||
|
||||
/* This function runs once at shutdown. */
|
||||
void SDL_AppQuit(void *appstate, SDL_AppResult result)
|
||||
{
|
||||
SDL_CloseCamera(camera);
|
||||
SDL_DestroyTexture(texture);
|
||||
/* SDL will clean up the window/renderer for us. */
|
||||
}
|
||||
|
||||
BIN
vendor/sdl-3.2.10/examples/camera/01-read-and-draw/thumbnail.png
vendored
Normal file
BIN
vendor/sdl-3.2.10/examples/camera/01-read-and-draw/thumbnail.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 234 KiB |
Loading…
Add table
Add a link
Reference in a new issue