/*
#define SDL_MAIN_USE_CALLBACKS is a special macro in SDL3 that changes how your program’s main() function works.
Normally, in SDL, you write the main() function (or WinMain() on Windows) and run your game loop yourself.
When you define SDL_MAIN_USE_CALLBACKS before including SDL_main.h, you tell SDL :
Don’t expect a main() function — instead, I’ll give you a set of callback functions, and SDL will run the main loop for me.
*/
/*
When SDL_MAIN_USE_CALLBACKS is defined, SDL expects you to implement four specific functions:
SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]);
SDL_AppResult SDL_AppIterate(void* appstate);
SDL_AppResult SDL_AppEvent(void* appstate, SDL_Event* event);
void SDL_AppQuit(void* appstate, SDL_AppResult result);
*/
#define SDL_MAIN_USE_CALLBACKS
#include <SDL3/SDL_main.h>
#include <SDL3/SDL.h>
SDL_Window* window;
SDL_AppResult SDL_AppInit(void** appstate, int argc, char** argv)
{
// create a window
window = SDL_CreateWindow("create blank window with callbacks system in SDL3", 960, 540, SDL_WINDOW_RESIZABLE);
return SDL_APP_CONTINUE;
}
SDL_AppResult SDL_AppIterate(void* appstate)
{
return SDL_APP_CONTINUE;
}
SDL_AppResult SDL_AppEvent(void* appstate, SDL_Event* event)
{
// close the window on request
if (event->type == SDL_EVENT_WINDOW_CLOSE_REQUESTED)
{
return SDL_APP_SUCCESS;
}
return SDL_APP_CONTINUE;
}
void SDL_AppQuit(void* appstate, SDL_AppResult result)
{
// destroy the window
SDL_DestroyWindow(window);
}
/*
run:
*/