Init, errors & main callbacksSDL 3.2
SDL_AppIterate
A function YOU write: SDL calls it once per frame to update and draw.
Signature
SDL_AppResult SDL_AppIterate(void *appstate);
How it works
This is the body of your old while loop, minus the event handling (that moved to SDL_AppEvent). Measure the time since the last frame, update the game, draw, present, return.
SDL calls it as fast as it can, or at the monitor's rate if vsync is on. Return quickly: blocking here freezes the window.
Parameters
appstatevoid *
The pointer you stored in SDL_AppInit.
Return value
SDL_APP_CONTINUE to keep going; SDL_APP_SUCCESS or SDL_APP_FAILURE to end the program.
Example
example.cpp
1SDL_AppResult SDL_AppIterate(void* appstate) {
2 auto* app = static_cast<App*>(appstate);
3 Uint64 now = SDL_GetTicksNS();
4 float dt = (now - app->lastTick) / 1e9f;
5 app->lastTick = now;
6 update(*app, dt);
7 SDL_SetRenderDrawColor(app->renderer, 16, 18, 26, 255);
8 SDL_RenderClear(app->renderer);
9 draw(*app);
10 SDL_RenderPresent(app->renderer);
11 return SDL_APP_CONTINUE;
12}