{"id":13534818,"url":"https://github.com/robloach/sdl_app","last_synced_at":"2025-04-02T00:30:57.621Z","repository":{"id":66036530,"uuid":"584086219","full_name":"RobLoach/SDL_App","owner":"RobLoach","description":"Application wrapper for SDL to unify desktop, mobile, and web SDL code.","archived":true,"fork":false,"pushed_at":"2024-04-05T20:53:53.000Z","size":17,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-05T21:42:14.196Z","etag":null,"topics":["sdl","sdl2"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"zlib","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RobLoach.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-01T09:36:45.000Z","updated_at":"2024-07-06T05:42:59.168Z","dependencies_parsed_at":"2024-07-06T05:42:56.379Z","dependency_job_id":null,"html_url":"https://github.com/RobLoach/SDL_App","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobLoach%2FSDL_App","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobLoach%2FSDL_App/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobLoach%2FSDL_App/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobLoach%2FSDL_App/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RobLoach","download_url":"https://codeload.github.com/RobLoach/SDL_App/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222784453,"owners_count":17037192,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["sdl","sdl2"],"created_at":"2024-08-01T08:00:43.237Z","updated_at":"2024-11-02T22:31:01.396Z","avatar_url":"https://github.com/RobLoach.png","language":"C","funding_links":[],"categories":["Libraries"],"sub_categories":[],"readme":"# SDL_App\n\nApplication wrapper for [SDL](https://libsdl.org/) to accomodate desktop, mobile, and web.\n\n## Deprecated\n\nWith SDL3, this is no longer required as you can use `SDL_MAIN_USE_CALLBACKS`. See https://github.com/Ravbug/sdl3-sample for a demonstration.\n\n## Introduction\n\nWhen building SDL applications for desktop, mobile, and web, there are subtle differences to accomodate the application workflow. [*SDL_App.h*](include/SDL_App.h) aims to clean up those differences, and make the code easier to read for a unified application entry. This pattern is inspired by [sokol_app](https://github.com/floooh/sokol#sokol_apph).\n\n## Example\n\n``` c\n#include \u003cSDL2/SDL.h\u003e\n\n#define SDL_APP_IMPLEMENTATION\n#include \"SDL_App.h\"\n\ntypedef struct AppData {\n    SDL_Window* window;\n    SDL_Renderer* renderer;\n} AppData;\n\nSDL_bool Init(void* userData) {\n    SDL_Init(SDL_INIT_EVERYTHING);\n\n    AppData* appData = (AppData*)userData;\n    appData-\u003ewindow = SDL_CreateWindow(\"SDL_App: Example\", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 450, SDL_WINDOW_SHOWN);\n    appData\u003erenderer = SDL_CreateRenderer(appData-\u003ewindow, -1, SDL_RENDERER_PRESENTVSYNC);\n\n    return SDL_TRUE;\n}\n\nSDL_bool Update(void* userData) {\n    AppData* appData = (AppData*)userData;\n\n    SDL_Event event;\n    while (SDL_PollEvent(\u0026event) != 0) {\n        switch (event.type) {\n            case SDL_QUIT:\n                return SDL_FALSE;\n        }\n    }\n\n    SDL_SetRenderDrawColor(appData-\u003erenderer, 102, 191, 255, 255);\n    SDL_RenderClear(appData-\u003erenderer);\n    SDL_RenderPresent(appData-\u003erenderer);\n\n    return SDL_TRUE;\n}\n\nvoid Close(void* userData) {\n    AppData* appData = (AppData*)userData;\n    SDL_DestroyRenderer(appData-\u003erenderer);\n    SDL_DestroyWindow(appData-\u003ewindow);\n    SDL_Quit();\n}\n\nSDL_App Main(int argc, char* argv[]) {\n    return (SDL_App) {\n        .init = Init,\n        .update = Update,\n        .close = Close,\n        .userData = SDL_malloc(sizeof(AppData)), // Optional\n    };\n}\n```\n\n## API\n\n### `SDL_App Main(int argc, char* argv[])`\n\nRather than having your own `int main()`, define your own `Main` function.\n\n``` c\nSDL_App Main(int argc, char* argv[]) {\n    return (SDL_App) {\n        .init = Init,               // The init callback that is called when the application initializes\n        .update = Update,           // The update callback that is called when the application should render\n        .close = Close,             // The close callback which is called when the application is closed\n        .userData = NULL            // Custom user data that is passed through all the callbacks (Optional)\n    };\n}\n```\n\n## License\n\n*SDL_App* is licensed under an unmodified zlib/libpng license, which is an OSI-certified, BSD-like license that allows static linking with closed source software. Check [LICENSE](LICENSE) for further details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobloach%2Fsdl_app","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobloach%2Fsdl_app","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobloach%2Fsdl_app/lists"}