SDL 3.0
|
#include <SDL3/SDL_stdinc.h>
#include <SDL3/SDL_events.h>
#include <SDL3/SDL_begin_code.h>
#include <SDL3/SDL_close_code.h>
Go to the source code of this file.
Macros | |
#define | SDLMAIN_DECLSPEC |
Typedefs | |
typedef int(* | SDL_AppInit_func) (int argc, char *argv[]) |
typedef int(* | SDL_AppIterate_func) (void) |
typedef int(* | SDL_AppEvent_func) (const SDL_Event *event) |
typedef void(* | SDL_AppQuit_func) (void) |
typedef int(* | SDL_main_func) (int argc, char *argv[]) |
Functions | |
SDLMAIN_DECLSPEC int | SDL_main (int argc, char *argv[]) |
void | SDL_SetMainReady (void) |
int | SDL_RunApp (int argc, char *argv[], SDL_main_func mainFunction, void *reserved) |
int | SDL_EnterAppMainCallbacks (int argc, char *argv[], SDL_AppInit_func appinit, SDL_AppIterate_func appiter, SDL_AppEvent_func appevent, SDL_AppQuit_func appquit) |
Redefine main() on some platforms so that it is called by SDL.
The application's main() function must be called with C linkage, and should be declared like this:
Definition in file SDL_main.h.
#define SDLMAIN_DECLSPEC |
Definition at line 134 of file SDL_main.h.
typedef int(* SDL_AppEvent_func) (const SDL_Event *event) |
Definition at line 163 of file SDL_main.h.
typedef int(* SDL_AppInit_func) (int argc, char *argv[]) |
Definition at line 161 of file SDL_main.h.
typedef int(* SDL_AppIterate_func) (void) |
Definition at line 162 of file SDL_main.h.
typedef void(* SDL_AppQuit_func) (void) |
Definition at line 164 of file SDL_main.h.
typedef int(* SDL_main_func) (int argc, char *argv[]) |
You can (optionally!) define SDL_MAIN_USE_CALLBACKS before including SDL_main.h, and then your application will not have a standard "main" entry point. Instead, it will operate as a collection of functions that are called as necessary by the system. On some platforms, this is just a layer where SDL drives your program instead of your program driving SDL, on other platforms this might hook into the OS to manage the lifecycle. Programs on most platforms can use whichever approach they prefer, but the decision boils down to:
This is up to the app; both approaches are considered valid and supported ways to write SDL apps.
If using the callbacks, don't define a "main" function. Instead, implement the functions listed below in your program. The prototype for the application's main() function
Definition at line 351 of file SDL_main.h.
|
extern |
An entry point for SDL's use in SDL_MAIN_USE_CALLBACKS.
Generally, you should not call this function directly. This only exists to hand off work into SDL as soon as possible, where it has a lot more control and functionality available, and make the inline code in SDL_main.h as small as possible.
Not all platforms use this, it's actual use is hidden in a magic header-only library, and you should not call this directly unless you really know what you're doing.
argc | standard Unix main argc |
argv | standard Unix main argv |
appinit | The application's SDL_AppInit function |
appiter | The application's SDL_AppIterate function |
appevent | The application's SDL_AppEvent function |
appquit | The application's SDL_AppQuit function |
\threadsafety It is not safe to call this anywhere except as the only function call in SDL_main.
|
extern |
Referenced by main().
|
extern |
Initializes and launches an SDL application, by doing platform-specific initialization before calling your mainFunction and cleanups after it returns, if that is needed for a specific platform, otherwise it just calls mainFunction.
You can use this if you want to use your own main() implementation without using SDL_main (like when using SDL_MAIN_HANDLED). When using this, you do not need SDL_SetMainReady().
argc | The argc parameter from the application's main() function, or 0 if the platform's main-equivalent has no argc |
argv | The argv parameter from the application's main() function, or NULL if the platform's main-equivalent has no argv |
mainFunction | Your SDL app's C-style main(), an SDL_main_func. NOT the function you're calling this from! Its name doesn't matter, but its signature must be like int my_main(int argc, char* argv[]) |
reserved | should be NULL (reserved for future use, will probably be platform-specific then) |
Referenced by main().
|
extern |
Circumvent failure of SDL_Init() when not using SDL_main() as an entry point.
This function is defined in SDL_main.h, along with the preprocessor rule to redefine main() as SDL_main(). Thus to ensure that your main() function will not be changed it is necessary to define SDL_MAIN_HANDLED before including SDL.h.