[
  {
    "path": ".github/workflows/android-build.yml",
    "content": "name: Build Sample for Android\r\n\r\non: [push, pull_request]\r\n\r\njobs:\r\n  apk:\r\n    name: Apk Build\r\n    runs-on: ubuntu-latest\r\n\r\n    steps:\r\n      - uses: actions/checkout@v4\r\n        with:\r\n          submodules: recursive\r\n      - uses: actions/setup-java@v4\r\n        with:\r\n          distribution: 'temurin'\r\n          java-version: '17'\r\n\r\n      - name: Update the build.gradle\r\n        run:  |\r\n               cp build.gradle SDL/android-project/app/\r\n\r\n      - name: Build the APK\r\n        run: |\r\n              cd SDL/android-project/\r\n              ./gradlew assembleDebug\r\n\r\n      - name: Upload the APK\r\n        uses: actions/upload-artifact@v4\r\n        with: \r\n          name: app-debug.apk\r\n          path: SDL/android-project/app/build/outputs/apk/debug/app-debug.apk\r\n"
  },
  {
    "path": ".github/workflows/build.yml",
    "content": "name: Build Sample\non: [push, pull_request]\n\njobs:\n    build-win:\n        name: Build for Windows\n        runs-on: windows-latest\n        strategy:\n          fail-fast: false\n          matrix:\n              arch: [x64, ARM64]\n              target: [Windows]\n\n        steps:\n          - uses: actions/checkout@v4\n            with:\n                submodules: recursive\n          - name: Configure\n            run: cmake -DCMAKE_SYSTEM_NAME=${{ matrix.target }} -DCMAKE_SYSTEM_VERSION=\"10.0\" -A${{ matrix.arch }} -S . -B build\n          - name: Build\n            run: cmake --build build --target sdl-min --config Release\n          - name: Upload Build\n            uses: actions/upload-artifact@v4\n            if: ${{ matrix.target != 'WindowsStore' }}\n            with: \n                name: sdl-min-${{ matrix.target }}-${{ matrix.arch }}\n                path: |\n                    build/Release/*.exe\n                    build/Release/*.dll\n                    build/Release/*.ttf\n                    build/Release/*.ogg\n                    build/Release/*.svg\n                    \n    build-linux:\n        name: Build for Linux\n        runs-on: ubuntu-latest\n        steps:\n          - uses: actions/checkout@v4\n            with:\n                submodules: recursive\n          - name: Install Dependencies\n            run: |\n                sudo apt update\n                sudo apt install -y --no-install-recommends build-essential git cmake ninja-build gnome-desktop-testing libasound2-dev libpulse-dev libaudio-dev libjack-dev libsndio-dev libx11-dev libxext-dev libxrandr-dev libxcursor-dev libxfixes-dev libxi-dev libxss-dev libxkbcommon-dev libdrm-dev libgbm-dev libgl1-mesa-dev libgles2-mesa-dev libegl1-mesa-dev libdbus-1-dev libibus-1.0-dev libudev-dev fcitx-libs-dev libpipewire-0.3-dev libwayland-dev libdecor-0-dev liburing-dev libxtst-dev\n          - name: Configure\n            run: cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -S . -B build\n          - name: Build\n            run: cmake --build build --target sdl-min --config Release\n          - name: Upload Build\n            uses: actions/upload-artifact@v4\n            with: \n                name: sdl-min-Linux\n                path: |\n                    build/Release/sdl-min\n                    build/Release/*.so\n                    build/Release/*.ttf\n                    build/Release/*.ogg\n                    build/Release/*.svg\n\n    build-mac:\n        name: Build for Apple\n        runs-on: macos-14\n        strategy:\n          fail-fast: false\n          matrix:\n              target: [iOS, tvOS, visionOS, '']\n\n        steps:\n          - uses: actions/checkout@v4\n            with:\n                submodules: recursive\n          - name: Setup Xcode version\n            uses: maxim-lobanov/setup-xcode@v1.6.0\n            with:\n                xcode-version: \"16.1\"\n          - name: Configure\n            run: cmake -G \"Xcode\" -DCMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED=NO -DCMAKE_SYSTEM_NAME=${{ matrix.target }} -DCMAKE_OSX_ARCHITECTURES=\"arm64;x86_64\" -S . -B build\n          - name: Build\n            run: cmake --build build --target install --config Release\n          - name: Ad-Hoc Codesign\n            run: codesign -s - -f \"./build/release/sdl-min.app\" --deep\n          - name: Create DMG\n            run: | \n                cd build\n                hdiutil create -size 2g -srcfolder release -volname sdl_min_apple_${{ matrix.target }} sdl_min_apple_${{ matrix.target }}.dmg\n          - name: Upload Build\n            uses: actions/upload-artifact@v4\n            with: \n                name: sdl-min-apple-${{ matrix.target }}\n                path: build/*.dmg\n"
  },
  {
    "path": ".github/workflows/web-build.yml",
    "content": "name: Build Sample For Web\non: [push, pull_request]\n\njobs:\n  build-web:\n    name: Build demo for Web\n    runs-on: ubuntu-latest\n    steps:\n      - name: Checkout code\n        uses: actions/checkout@v4\n        with:\n          submodules: recursive\n      - name: Get Emscripten\n        run: |\n          git clone https://github.com/emscripten-core/emsdk.git --depth=1\n          cd emsdk\n          ./emsdk install tot\n          ./emsdk activate tot\n      - name: Build for web\n        run: |\n          source emsdk/emsdk_env.sh\n          emcmake cmake -S . -B build\n          cmake --build build --parallel\n      - name: Prepare for upload\n        run: |\n           mkdir _site\n           mv build/sdl-min.html _site/index.html\n           mv build/sdl-* _site/\n      - name: Fix permissions\n        run: |\n         chmod -c -R +rX \"_site/\" | while read line; do\n           echo \"::warning title=Invalid file permissions automatically fixed::$line\"\n         done\n      - name: Upload \n        uses: actions/upload-pages-artifact@v3\n        with:\n          path: _site/\n        \n # Deploy job\n  deploy:\n    # Add a dependency to the build job\n    needs: build-web\n\n    # Grant GITHUB_TOKEN the permissions required to make a Pages deployment\n    permissions:\n      pages: write      # to deploy to Pages\n      id-token: write   # to verify the deployment originates from an appropriate source\n\n    # Deploy to the github-pages environment\n    environment:\n      name: github-pages\n      url: ${{ steps.deployment.outputs.page_url }}\n\n    # Specify runner + deployment step\n    runs-on: ubuntu-latest\n    steps:\n      - name: Deploy to GitHub Pages\n        id: deployment\n        uses: actions/deploy-pages@v4 # or the latest \"vX.X.X\" version tag for this action\n"
  },
  {
    "path": ".gitignore",
    "content": ".DS_Store\nbuild/\n"
  },
  {
    "path": ".gitmodules",
    "content": "[submodule \"SDL\"]\n\tpath = SDL\n\turl = https://github.com/libsdl-org/SDL\n[submodule \"SDL_ttf\"]\n\tpath = SDL_ttf\n\turl = https://github.com/libsdl-org/SDL_ttf\n[submodule \"SDL_mixer\"]\n\tpath = SDL_mixer\n\turl = https://github.com/libsdl-org/SDL_mixer\n[submodule \"SDL_image\"]\n\tpath = SDL_image\n\turl = https://github.com/libsdl-org/SDL_image\n"
  },
  {
    "path": "CMakeLists.txt",
    "content": "cmake_minimum_required(VERSION 3.16)\n\n# set the output directory for built objects.\n# This makes sure that the dynamic library goes into the build directory automatically.\nset(CMAKE_RUNTIME_OUTPUT_DIRECTORY \"${CMAKE_BINARY_DIR}/$<CONFIGURATION>\")\nset(CMAKE_LIBRARY_OUTPUT_DIRECTORY \"${CMAKE_BINARY_DIR}/$<CONFIGURATION>\")\n\n# prevent installing to system directories. \nset(CMAKE_INSTALL_PREFIX \"${CMAKE_BINARY_DIR}\" CACHE INTERNAL \"\")\n\n# Declare the project\nproject(sdl-min)\n\nif ((APPLE AND NOT CMAKE_SYSTEM_NAME MATCHES \"Darwin\") OR EMSCRIPTEN)\n    set(BUILD_SHARED_LIBS OFF CACHE INTERNAL \"\")    # Disable shared builds on platforms where it does not make sense to use them\n    set(SDL_SHARED OFF)\nelse()\n    set(SDL_SHARED ON)\nendif()\n\nif(MSVC)\n    if(NOT CMAKE_GENERATOR STREQUAL \"Ninja\")\n        add_definitions(/MP)\t\t\t\t# parallelize each target, unless Ninja is the generator\n    endif()\nendif()\n\n# Set the name of the executable\nset(EXECUTABLE_NAME ${PROJECT_NAME})\n\n# Create an executable or a shared library based on the platform and add our sources to it\nif (ANDROID)\n\t# The SDL java code is hardcoded to load libmain.so on android, so we need to change EXECUTABLE_NAME\n\tset(EXECUTABLE_NAME main)\n\tadd_library(${EXECUTABLE_NAME} SHARED)\nelse()\n\tadd_executable(${EXECUTABLE_NAME})\nendif()\n\n# Add your sources to the target\ntarget_sources(${EXECUTABLE_NAME} \nPRIVATE \n    src/main.cpp\n    src/iosLaunchScreen.storyboard\n)\n# What is iosLaunchScreen.storyboard? This file describes what Apple's mobile platforms\n# should show the user while the application is starting up. If you don't include one,\n# then you get placed in a compatibility mode that does not allow HighDPI.\n# This file is referenced inside Info.plist.in, where it is marked as the launch screen file.\n# It is also ignored on non-Apple platforms. \n\n# To get an app icon on Apple platforms, add it to your executable.\n# Afterward, the image file in Info.plist.in.\nif(APPLE)\n    target_sources(\"${EXECUTABLE_NAME}\" PRIVATE \"src/logo.png\")\nendif()\n\n# Set C++ version\ntarget_compile_features(${EXECUTABLE_NAME} PUBLIC cxx_std_20)\n\n# on Web targets, we need CMake to generate a HTML webpage. \nif(EMSCRIPTEN)\n\tset(CMAKE_EXECUTABLE_SUFFIX \".html\" CACHE INTERNAL \"\")\nendif()\n\n# Configure SDL by calling its CMake file.\n# we use EXCLUDE_FROM_ALL so that its install targets and configs don't\n# pollute upwards into our configuration.\nadd_subdirectory(SDL EXCLUDE_FROM_ALL)\n\n# If you don't want SDL_ttf, then remove this section.\nset(SDLTTF_VENDORED ON) # tell SDL_ttf to build its own dependencies\nadd_subdirectory(SDL_ttf EXCLUDE_FROM_ALL)\t\n\n# SDL_mixer (used for playing audio)\nset(SDLMIXER_MIDI_NATIVE OFF)     # disable formats we don't use to make the build faster and smaller. Also some of these don't work on all platforms so you'll need to do some experimentation.\nset(SDLMIXER_GME OFF)\nset(SDLMIXER_WAVPACK OFF)     \nset(SDLMIXER_MOD OFF)\nset(SDLMIXER_MOD_XMP OFF)\nset(SDLMIXER_OPUS OFF)\nset(SDLMIXER_MP3_MPG123 OFF)\nset(SDLMIXER_VORBIS_VORBISFILE OFF)\nset(SDLMIXER_FLAC_LIBFLAC OFF)\nset(SDLMIXER_VENDORED ON)   # tell SDL_mixer to build its own dependencies\nadd_subdirectory(SDL_mixer EXCLUDE_FROM_ALL)\n\n# SDL_image (used for loading various image formats)\nset(SDLIMAGE_VENDORED ON)\nset(SDLIMAGE_AVIF OFF)\t# disable formats we don't use to make the build faster and smaller.\nset(SDLIMAGE_BMP OFF)\nset(SDLIMAGE_JPG OFF)\nset(SDLIMAGE_WEBP OFF)\nset(SDLIMAGE_PNG_LIBPNG OFF)    # SDL3 includes built-in support for loading PNGs. If you need more than what that supports, enable this option.\nadd_subdirectory(SDL_image EXCLUDE_FROM_ALL)\n\n# Link SDL to our executable. This also makes its include directory available to us. \ntarget_link_libraries(${EXECUTABLE_NAME} PUBLIC \n\tSDL3_ttf::SDL3_ttf      # remove if you are not using SDL_ttf\n\tSDL3_mixer::SDL3_mixer  # remove if you are not using SDL_mixer\n\tSDL3_image::SDL3_image\t# remove if you are not using SDL_image\n    SDL3::SDL3              # If using satelite libraries, SDL must be the last item in the list. \n)\n\n# Dealing with assets\n# We have some non-code resources that our application needs in order to work. How we deal with those differs per platform.\nif (APPLE)\n    # on Apple targets, the application bundle has a \"resources\" subfolder where we can place our assets.\n    # SDL_GetBasePath() gives us easy access to that location.\n    set(input_root \"${CMAKE_CURRENT_LIST_DIR}/src\")\n    macro(add_resource FILE)\n        file(RELATIVE_PATH relpath \"${input_root}\" \"${FILE}\")\n        get_filename_component(relpath \"${relpath}\" DIRECTORY)\n        target_sources(${EXECUTABLE_NAME} PRIVATE ${FILE})\n        set_property(SOURCE ${FILE} PROPERTY MACOSX_PACKAGE_LOCATION \"Resources/${relpath}\")\n    endmacro()\n    add_resource(\"${CMAKE_CURRENT_LIST_DIR}/src/Inter-VariableFont.ttf\")\n    add_resource(\"${CMAKE_CURRENT_LIST_DIR}/src/the_entertainer.ogg\")\n    add_resource(\"${CMAKE_CURRENT_LIST_DIR}/src/gs_tiger.svg\")\nelseif(EMSCRIPTEN)\n    # on the web, we have to put the files inside of the webassembly\n    # somewhat unintuitively, this is done via a linker argument.\n    target_link_libraries(${EXECUTABLE_NAME} PRIVATE \n        \"--preload-file \\\"${CMAKE_CURRENT_LIST_DIR}/src/Inter-VariableFont.ttf@/\\\"\"\n        \"--preload-file \\\"${CMAKE_CURRENT_LIST_DIR}/src/the_entertainer.ogg@/\\\"\"\n        \"--preload-file \\\"${CMAKE_CURRENT_LIST_DIR}/src/gs_tiger.svg@/\\\"\"\n    )\nelse()\n    if (ANDROID)\n        if (NOT MOBILE_ASSETS_DIR)\n            message(FATAL_ERROR \"Building for Android, but MOBILE_ASSETS_DIR is not set\")\n        endif()\n        file(MAKE_DIRECTORY \"${MOBILE_ASSETS_DIR}\")    # we need to create the project Assets dir otherwise CMake won't copy our assets.\n    endif()\n\n    \n    macro(copy_helper filename)\n        if (ANDROID)\n            # MOBILE_ASSETS_DIR is set in the gradle file via the cmake command line and points to the Android Studio Assets folder. \n            # when we copy assets there, the Android build pipeline knows to add them to the apk. \n            set(outname \"${MOBILE_ASSETS_DIR}/${filename}\")    \n        else()\n            # for platforms that do not have a good packaging format, all we can do is copy the assets to the process working directory.\n            set(outname \"${CMAKE_BINARY_DIR}/$<CONFIGURATION>/${filename}\")\n        endif()\n        add_custom_command(POST_BUILD\n            TARGET \"${EXECUTABLE_NAME}\"\n\t\t    COMMAND ${CMAKE_COMMAND} -E copy_if_different \"${CMAKE_CURRENT_LIST_DIR}/src/${filename}\" \"${outname}\"\n\t    )\n    endmacro()\n    copy_helper(\"Inter-VariableFont.ttf\")\n    copy_helper(\"the_entertainer.ogg\")\n    copy_helper(\"gs_tiger.svg\")\nendif()\n\n# set some extra configs for each platform\nset(RESOURCE_FILES \"src/logo.png\")\nif(IOS)\n    set(RESOURCE_FILES \"src/iosLaunchScreen.storyboard;src/logo.png\") # make the splash screen show up on iOS\nendif()\n\nset_target_properties(${EXECUTABLE_NAME} PROPERTIES \n    # On macOS, make a proper .app bundle instead of a bare executable\n    MACOSX_BUNDLE TRUE\n    # Set the Info.plist file for Apple Mobile platforms. Without this file, your app\n    # will not launch. \n    MACOSX_BUNDLE_INFO_PLIST \"${CMAKE_CURRENT_SOURCE_DIR}/src/Info.plist.in\"\n\n    # in Xcode, create a Scheme in the schemes dropdown for the app.\n    XCODE_GENERATE_SCHEME TRUE\n    # Identification for Xcode\n    XCODE_ATTRIBUTE_BUNDLE_IDENTIFIER \"com.ravbug.sdl3-sample\"\n\tXCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER \"com.ravbug.sdl3-sample\"\n\tXCODE_ATTRIBUTE_CURRENTYEAR \"${CURRENTYEAR}\"\n    RESOURCE \"${RESOURCE_FILES}\"\n)\n\n# on Visual Studio, set our app as the default project\nset_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT \"${EXECUTABLE_NAME}\")\n\n# On macOS Platforms, ensure that the bundle is valid for distribution by calling fixup_bundle.\n# note that fixup_bundle does not work on iOS, so you will want to use static libraries \n# or manually copy dylibs and set rpaths\nif(CMAKE_SYSTEM_NAME MATCHES \"Darwin\")\n    # tell Install about the target, otherwise fixup won't know about the transitive dependencies\n    install(TARGETS ${EXECUTABLE_NAME}\n    \tBUNDLE DESTINATION ./install COMPONENT Runtime\n   \t    RUNTIME DESTINATION ./install/bin COMPONENT Runtime\n    )\n\t\n    set(DEP_DIR \"${CMAKE_BINARY_DIR}\")  # where to look for dependencies when fixing up\n    INSTALL(CODE \n        \"include(BundleUtilities)\n        fixup_bundle(\\\"$<TARGET_BUNDLE_DIR:${EXECUTABLE_NAME}>\\\" \\\"\\\" \\\"${DEP_DIR}\\\")\n        \" \n    )\n    set(CPACK_GENERATOR \"DragNDrop\")\n    include(CPack)\nendif()\n"
  },
  {
    "path": "LICENSE",
    "content": "Creative Commons Legal Code\n\nCC0 1.0 Universal\n\n    CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE\n    LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN\n    ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS\n    INFORMATION ON AN \"AS-IS\" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES\n    REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS\n    PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM\n    THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED\n    HEREUNDER.\n\nStatement of Purpose\n\nThe laws of most jurisdictions throughout the world automatically confer\nexclusive Copyright and Related Rights (defined below) upon the creator\nand subsequent owner(s) (each and all, an \"owner\") of an original work of\nauthorship and/or a database (each, a \"Work\").\n\nCertain owners wish to permanently relinquish those rights to a Work for\nthe purpose of contributing to a commons of creative, cultural and\nscientific works (\"Commons\") that the public can reliably and without fear\nof later claims of infringement build upon, modify, incorporate in other\nworks, reuse and redistribute as freely as possible in any form whatsoever\nand for any purposes, including without limitation commercial purposes.\nThese owners may contribute to the Commons to promote the ideal of a free\nculture and the further production of creative, cultural and scientific\nworks, or to gain reputation or greater distribution for their Work in\npart through the use and efforts of others.\n\nFor these and/or other purposes and motivations, and without any\nexpectation of additional consideration or compensation, the person\nassociating CC0 with a Work (the \"Affirmer\"), to the extent that he or she\nis an owner of Copyright and Related Rights in the Work, voluntarily\nelects to apply CC0 to the Work and publicly distribute the Work under its\nterms, with knowledge of his or her Copyright and Related Rights in the\nWork and the meaning and intended legal effect of CC0 on those rights.\n\n1. Copyright and Related Rights. A Work made available under CC0 may be\nprotected by copyright and related or neighboring rights (\"Copyright and\nRelated Rights\"). Copyright and Related Rights include, but are not\nlimited to, the following:\n\n  i. the right to reproduce, adapt, distribute, perform, display,\n     communicate, and translate a Work;\n ii. moral rights retained by the original author(s) and/or performer(s);\niii. publicity and privacy rights pertaining to a person's image or\n     likeness depicted in a Work;\n iv. rights protecting against unfair competition in regards to a Work,\n     subject to the limitations in paragraph 4(a), below;\n  v. rights protecting the extraction, dissemination, use and reuse of data\n     in a Work;\n vi. database rights (such as those arising under Directive 96/9/EC of the\n     European Parliament and of the Council of 11 March 1996 on the legal\n     protection of databases, and under any national implementation\n     thereof, including any amended or successor version of such\n     directive); and\nvii. other similar, equivalent or corresponding rights throughout the\n     world based on applicable law or treaty, and any national\n     implementations thereof.\n\n2. Waiver. To the greatest extent permitted by, but not in contravention\nof, applicable law, Affirmer hereby overtly, fully, permanently,\nirrevocably and unconditionally waives, abandons, and surrenders all of\nAffirmer's Copyright and Related Rights and associated claims and causes\nof action, whether now known or unknown (including existing as well as\nfuture claims and causes of action), in the Work (i) in all territories\nworldwide, (ii) for the maximum duration provided by applicable law or\ntreaty (including future time extensions), (iii) in any current or future\nmedium and for any number of copies, and (iv) for any purpose whatsoever,\nincluding without limitation commercial, advertising or promotional\npurposes (the \"Waiver\"). Affirmer makes the Waiver for the benefit of each\nmember of the public at large and to the detriment of Affirmer's heirs and\nsuccessors, fully intending that such Waiver shall not be subject to\nrevocation, rescission, cancellation, termination, or any other legal or\nequitable action to disrupt the quiet enjoyment of the Work by the public\nas contemplated by Affirmer's express Statement of Purpose.\n\n3. Public License Fallback. Should any part of the Waiver for any reason\nbe judged legally invalid or ineffective under applicable law, then the\nWaiver shall be preserved to the maximum extent permitted taking into\naccount Affirmer's express Statement of Purpose. In addition, to the\nextent the Waiver is so judged Affirmer hereby grants to each affected\nperson a royalty-free, non transferable, non sublicensable, non exclusive,\nirrevocable and unconditional license to exercise Affirmer's Copyright and\nRelated Rights in the Work (i) in all territories worldwide, (ii) for the\nmaximum duration provided by applicable law or treaty (including future\ntime extensions), (iii) in any current or future medium and for any number\nof copies, and (iv) for any purpose whatsoever, including without\nlimitation commercial, advertising or promotional purposes (the\n\"License\"). The License shall be deemed effective as of the date CC0 was\napplied by Affirmer to the Work. Should any part of the License for any\nreason be judged legally invalid or ineffective under applicable law, such\npartial invalidity or ineffectiveness shall not invalidate the remainder\nof the License, and in such case Affirmer hereby affirms that he or she\nwill not (i) exercise any of his or her remaining Copyright and Related\nRights in the Work or (ii) assert any associated claims and causes of\naction with respect to the Work, in either case contrary to Affirmer's\nexpress Statement of Purpose.\n\n4. Limitations and Disclaimers.\n\n a. No trademark or patent rights held by Affirmer are waived, abandoned,\n    surrendered, licensed or otherwise affected by this document.\n b. Affirmer offers the Work as-is and makes no representations or\n    warranties of any kind concerning the Work, express, implied,\n    statutory or otherwise, including without limitation warranties of\n    title, merchantability, fitness for a particular purpose, non\n    infringement, or the absence of latent or other defects, accuracy, or\n    the present or absence of errors, whether or not discoverable, all to\n    the greatest extent permissible under applicable law.\n c. Affirmer disclaims responsibility for clearing rights of other persons\n    that may apply to the Work or any use thereof, including without\n    limitation any person's Copyright and Related Rights in the Work.\n    Further, Affirmer disclaims responsibility for obtaining any necessary\n    consents, permissions or other rights required for any use of the\n    Work.\n d. Affirmer understands and acknowledges that Creative Commons is not a\n    party to this document and has no duty or obligation with respect to\n    this CC0 or use of the Work.\n"
  },
  {
    "path": "README.md",
    "content": "## SDL3 App From Source Minimal Example\nThis is a minimal example for building and using SDL3, SDL_Mixer, SDL_Image, and SDL_ttf_ from source \nusing C++ and CMake. It also demonstrates setting up things like macOS/iOS\nbundles.\nSee [src/main.cpp](src/main.cpp) for the code. \n\n### Building And Running\nAre you a complete beginner? If so, read [this](https://github.com/Ravbug/sdl3-sample/wiki/Setting-up-your-computer)!\nOtherwise, install CMake and your favorite compiler, and follow the commands below:\n```sh\n# You need to clone with submodules, otherwise SDL will not download.\ngit clone https://github.com/Ravbug/sdl3-sample --depth=1 --recurse-submodules\ncd sdl3-sample\ncmake -S . -B build\n```\nYou can also use an init script inside [`config/`](config/). Then open the IDE project inside `build/` \n(If you had CMake generate one) and run!\n\n## Supported Platforms\nI have tested the following:\n| Platform | Architecture | Generator |\n| --- | --- | --- |\n| macOS | x86_64, arm64 | Xcode |\n| iOS | x86_64, arm64 | Xcode |\n| tvOS | x86_64, arm64 | Xcode |\n| visionOS* | arm64 | Xcode |\n| Windows | x86_64, arm64 | Visual Studio |\n| Linux | x86_64, arm64 | Ninja, Make |\n| Web* | wasm | Ninja, Make |\n| Android* | x86, x64, arm, arm64 | Ninja via Android Studio |\n\n*See further instructions in [`config/`](config/)\n\nNote: UWP support was [removed from SDL3](https://github.com/libsdl-org/SDL/pull/10731) during its development. For historical reasons, you can get a working UWP sample via this commit: [df270da](https://github.com/Ravbug/sdl3-sample/tree/df270daa8d6d48426e128e50c73357dfdf89afbf)\n\n## Updating SDL\nJust update the submodule:\n```sh\ncd SDL\ngit pull\ncd ..\n\ncd SDL_ttf\ngit pull\n```\nYou don't need to use a submodule, you can also copy the source in directly. This\nrepository uses a submodule to keep its size to a minimum.\n\n## Reporting issues\nIs something not working? Create an Issue or send a Pull Request on this repository!\n"
  },
  {
    "path": "build.gradle",
    "content": "def buildAsLibrary = project.hasProperty('BUILD_AS_LIBRARY');\r\ndef buildAsApplication = !buildAsLibrary\r\nif (buildAsApplication) {\r\n    apply plugin: 'com.android.application'\r\n}\r\nelse {\r\n    apply plugin: 'com.android.library'\r\n}\r\n\r\nandroid {\r\n    compileSdkVersion 34\r\n    if (buildAsApplication) {\r\n        namespace \"org.libsdl.app\"\r\n    }\r\n    defaultConfig {\r\n        minSdkVersion 21\r\n        targetSdkVersion 34\r\n        versionCode 1\r\n        versionName \"1.0\"\r\n        externalNativeBuild {\r\n            cmake {\r\n                arguments \"-DANDROID_APP_PLATFORM=android-16\", \"-DANDROID_STL=c++_static\", \"-DCMAKE_VERBOSE_MAKEFILE=ON\", \"-DMOBILE_ASSETS_DIR=${System.getProperty(\"user.dir\")}/app/src/main/assets\"\r\n                // abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'\r\n                // abiFilters 'arm64-v8a'\r\n            }\r\n        }\r\n    }\r\n    buildTypes {\r\n        release {\r\n            minifyEnabled false\r\n            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'\r\n        }\r\n    }\r\n    applicationVariants.all { variant ->\r\n        tasks[\"merge${variant.name.capitalize()}Assets\"]\r\n                .dependsOn(\"externalNativeBuild${variant.name.capitalize()}\")\r\n    }\r\n    if (!project.hasProperty('EXCLUDE_NATIVE_LIBS')) {\r\n        sourceSets.main {\r\n            jniLibs.srcDir 'libs'\r\n        }\r\n        externalNativeBuild {\r\n            // ndkBuild {\r\n            //     path 'jni/Android.mk'\r\n            // }\r\n            cmake {\r\n                path \"../../../CMakeLists.txt\"\r\n                version \"3.22.1\"\r\n            }\r\n        }\r\n\r\n    }\r\n    lintOptions {\r\n        abortOnError false\r\n    }\r\n\r\n    if (buildAsLibrary) {\r\n        libraryVariants.all { variant ->\r\n            variant.outputs.each { output ->\r\n                def outputFile = output.outputFile\r\n                if (outputFile != null && outputFile.name.endsWith(\".aar\")) {\r\n                    def fileName = \"org.libsdl.app.aar\";\r\n                    output.outputFile = new File(outputFile.parent, fileName);\r\n                }\r\n            }\r\n        }\r\n    }\r\n}\r\n\r\ndependencies {\r\n    implementation fileTree(include: ['*.jar'], dir: 'libs')\r\n}\r\n"
  },
  {
    "path": "config/README.md",
    "content": "# How to use these scripts\r\n\r\nFor the most part, just run the scripts in this directory from this directory. \r\n\r\n## Notes:\r\n- visionOS\r\n\t- Requires CMake 3.28 or newer\r\n- Web\r\n \t1. Install emsdk somewhere.\r\n  \t2. On Windows hosts, run `config-web-win.bat` via the `emcmdprompt.bat` cmd in the emsdk root directory\r\n\t3. On Unix hosts, first run `source emsdk_env.sh` (found in the emsdk root directory), then run `config-web-unix.sh` \r\n\t4. After the build completes, use `python3 -m http.server` in the build directory to make the page accessible.\r\n- Android\r\n\t- There is no easy CMake config for this platform. Instead, follow the steps as outlined below. See the android GitHub action for more details. \r\n\t1. Install Android Studio + NDK from https://developer.android.com/studio\r\n \t2. Copy `build.gradle` to `SDL/android-project/app/`. If you look inside `build.gradle`, you'll see `\"../../../CMakeLists.txt\"` as the path to the CMakeLists file. This points to the CMakeLists in this repo's root directory after it is copied. \r\n  \t3. `cd SDL/android-project/`\r\n  \t4. `./gradlew assembleDebug`. You'll get an apk which you can then install onto a device. \r\n"
  },
  {
    "path": "config/config-generic.sh",
    "content": "#!/bin/bash\ncd \"${0%/*}\"/\n\ncmake -B \"../build/`uname`\" -S .."
  },
  {
    "path": "config/config-ios-xcode.sh",
    "content": "#!/bin/bash\ncd \"${0%/*}\"\n\ncmake -G \"Xcode\" -DCMAKE_SYSTEM_NAME=\"iOS\" -B ../build/ios -S ..\n"
  },
  {
    "path": "config/config-mac-xcode.sh",
    "content": "#!/bin/bash\ncd \"${0%/*}\"\n\ncmake -G \"Xcode\" -B ../build/mac  -S .."
  },
  {
    "path": "config/config-tvos-xcode.sh",
    "content": "#!/bin/bash\ncd \"${0%/*}\"\n\ncmake -G \"Xcode\" -DCMAKE_SYSTEM_NAME=\"tvOS\" -B ../build/tvos -S ..\n"
  },
  {
    "path": "config/config-visionos-xcode.sh",
    "content": "#!/bin/bash\n\n# note: requires CMake 3.28 or newer\n\ncd \"${0%/*}\"\n\ncmake -G \"Xcode\" -DCMAKE_SYSTEM_NAME=\"visionOS\" -S .. -B ../build/visionOS\n"
  },
  {
    "path": "config/config-web-unix.sh",
    "content": "#!/bin/bash\ncd \"${0%/*}\"\n\nemcmake cmake -S .. -B ../build/web"
  },
  {
    "path": "config/config-web-win.bat",
    "content": "@echo OFF\n\nemcmake cmake -S .. -B ..\\build\\web"
  },
  {
    "path": "config/config-win.bat",
    "content": "@echo OFF\n\ncmake -S .. -B ..\\build\\win"
  },
  {
    "path": "src/Info.plist.in",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>NSHighResolutionCapable</key>\n\t<true/>\n\t<key>CFBundleDevelopmentRegion</key>\n\t<string>$(DEVELOPMENT_LANGUAGE)</string>\n\t<key>UILaunchStoryboardName</key>\n\t<string>iosLaunchScreen</string>\n\t<key>CFBundleExecutable</key>\n\t<string>$(EXECUTABLE_NAME)</string>\n\t<key>CFBundleIconFile</key>\n\t<string></string>\n\t<key>CFBundleIdentifier</key>\n\t<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>\n\t<key>CFBundleInfoDictionaryVersion</key>\n\t<string>6.0</string>\n\t<key>CFBundleName</key>\n\t<string>$(PRODUCT_NAME)</string>\n\t<key>CFBundlePackageType</key>\n\t<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>\n\t<key>CFBundleShortVersionString</key>\n\t<string>1.0</string>\n\t<key>CFBundleVersion</key>\n\t<string>1</string>\n\t<key>LSMinimumSystemVersion</key>\n\t<string>$(MACOSX_DEPLOYMENT_TARGET)</string>\n\t<key>NSHumanReadableCopyright</key>\n\t<string>Copyright © $(CURRENTYEAR) Ravbug. All rights reserved.</string>\n\t<key>NSSupportsAutomaticTermination</key>\n\t<true/>\n\t<key>NSSupportsSuddenTermination</key>\n\t<true/>\n\t<key>CFBundleIconFile</key>\n\t<string>logo.png</string>\n    <key>UIRequiresFullScreen</key>\n    <true/>\n\t<key>UISupportedInterfaceOrientations</key>\n\t<array>\n\t\t<string>UIInterfaceOrientationLandscapeLeft</string>\n\t\t<string>UIInterfaceOrientationLandscapeRight</string>\n\t</array>\n</dict>\n</plist>\n"
  },
  {
    "path": "src/attributions.txt",
    "content": "\"The Entertainer\" Kevin MacLeod (incompetech.com)\r\nLicensed under Creative Commons: By Attribution 4.0 License\r\n\r\nhttp://creativecommons.org/licenses/by/4.0/\r\n\r\n\r\n\"Tiger from the Ghostscript examples\" (gs_tiger.svg) is under the terms of the \r\nGNU Affero General Public License as published by the Free Software Foundation; \r\neither version 3 of the License, or any later version. This work is distributed \r\nin the hope that it will be useful, but without any warranty; without even the \r\nimplied warranty of merchantability or fitness for a particular purpose. \r\nSee version 3 of the GNU Affero General Public License for more details.\r\n\r\n"
  },
  {
    "path": "src/iosLaunchScreen.storyboard",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<document type=\"com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB\" version=\"3.0\" toolsVersion=\"23504\" targetRuntime=\"iOS.CocoaTouch\" propertyAccessControl=\"none\" useAutolayout=\"YES\" launchScreen=\"YES\" useTraitCollections=\"YES\" useSafeAreas=\"YES\" colorMatched=\"YES\" initialViewController=\"01J-lp-oVM\">\n    <device id=\"retina6_12\" orientation=\"landscape\" appearance=\"light\"/>\n    <dependencies>\n        <plugIn identifier=\"com.apple.InterfaceBuilder.IBCocoaTouchPlugin\" version=\"23506\"/>\n        <capability name=\"documents saved in the Xcode 8 format\" minToolsVersion=\"8.0\"/>\n    </dependencies>\n    <scenes>\n        <!--View Controller-->\n        <scene sceneID=\"EHf-IW-A2E\">\n            <objects>\n                <viewController id=\"01J-lp-oVM\" sceneMemberID=\"viewController\">\n                    <imageView key=\"view\" clipsSubviews=\"YES\" userInteractionEnabled=\"NO\" contentMode=\"scaleAspectFit\" horizontalHuggingPriority=\"251\" verticalHuggingPriority=\"251\" image=\"logo.png\" id=\"mAg-Nv-QPQ\">\n                        <rect key=\"frame\" x=\"0.0\" y=\"0.0\" width=\"852\" height=\"393\"/>\n                        <autoresizingMask key=\"autoresizingMask\" flexibleMaxX=\"YES\" flexibleMaxY=\"YES\"/>\n                    </imageView>\n                </viewController>\n                <placeholder placeholderIdentifier=\"IBFirstResponder\" id=\"iYj-Kq-Ea1\" userLabel=\"First Responder\" sceneMemberID=\"firstResponder\"/>\n            </objects>\n            <point key=\"canvasLocation\" x=\"53\" y=\"375\"/>\n        </scene>\n    </scenes>\n    <resources>\n        <image name=\"logo.png\" width=\"460\" height=\"460\"/>\n    </resources>\n</document>\n"
  },
  {
    "path": "src/main.cpp",
    "content": "#define SDL_MAIN_USE_CALLBACKS  // This is necessary for the new callbacks API. To use the legacy API, don't define this. \n#include <SDL3/SDL.h>\n#include <SDL3/SDL_main.h>\n#include <SDL3/SDL_init.h>\n#include <SDL3_ttf/SDL_ttf.h>\n#include <SDL3_mixer/SDL_mixer.h>\n#include <SDL3_image/SDL_image.h>\n#include <cmath>\n#include <string_view>\n#include <filesystem>\n#include <thread>\n\nconstexpr uint32_t windowStartWidth = 400;\nconstexpr uint32_t windowStartHeight = 400;\n\nstruct AppContext {\n    SDL_Window* window;\n    SDL_Renderer* renderer;\n    SDL_Texture* messageTex, *imageTex;\n    SDL_FRect messageDest;\n    SDL_AudioDeviceID audioDevice;\n    MIX_Track* track;\n    SDL_AppResult app_quit = SDL_APP_CONTINUE;\n};\n\nSDL_AppResult SDL_Fail(){\n    SDL_LogError(SDL_LOG_CATEGORY_CUSTOM, \"Error %s\", SDL_GetError());\n    return SDL_APP_FAILURE;\n}\n\nSDL_AppResult SDL_AppInit(void** appstate, int argc, char* argv[]) {\n    // init the library, here we make a window so we only need the Video capabilities.\n    if (not SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO)){\n        return SDL_Fail();\n    }\n    \n    // init TTF\n    if (not TTF_Init()) {\n        return SDL_Fail();\n    }\n    \n    // init Mixer\n    if (not MIX_Init()) {\n        return SDL_Fail();\n    }\n    \n    // create a window\n   \n    SDL_Window* window = SDL_CreateWindow(\"SDL Minimal Sample\", windowStartWidth, windowStartHeight, SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY);\n    if (not window){\n        return SDL_Fail();\n    }\n    \n    // create a renderer\n    SDL_Renderer* renderer = SDL_CreateRenderer(window, NULL);\n    if (not renderer){\n        return SDL_Fail();\n    }\n    \n    // load the font\n#if __ANDROID__\n    std::filesystem::path basePath = \"\";   // on Android we do not want to use basepath. Instead, assets are available at the root directory.\n#else\n    auto basePathPtr = SDL_GetBasePath();\n     if (not basePathPtr){\n        return SDL_Fail();\n    }\n     const std::filesystem::path basePath = basePathPtr;\n#endif\n\n    const auto fontPath = basePath / \"Inter-VariableFont.ttf\";\n    TTF_Font* font = TTF_OpenFont(fontPath.string().c_str(), 36);\n    if (not font) {\n        return SDL_Fail();\n    }\n\n    // render the font to a surface\n    const std::string_view text = \"Hello SDL!\";\n    SDL_Surface* surfaceMessage = TTF_RenderText_Solid(font, text.data(), text.length(), { 255,255,255 });\n\n    // make a texture from the surface\n    SDL_Texture* messageTex = SDL_CreateTextureFromSurface(renderer, surfaceMessage);\n\n    // we no longer need the font or the surface, so we can destroy those now.\n    TTF_CloseFont(font);\n    SDL_DestroySurface(surfaceMessage);\n\n    // load the SVG\n    auto svg_surface = IMG_Load((basePath / \"gs_tiger.svg\").string().c_str());\n    SDL_Texture* tex = SDL_CreateTextureFromSurface(renderer, svg_surface);\n    SDL_DestroySurface(svg_surface);\n    \n\n    // get the on-screen dimensions of the text. this is necessary for rendering it\n    auto messageTexProps = SDL_GetTextureProperties(messageTex);\n    SDL_FRect text_rect{\n            .x = 0,\n            .y = 0,\n            .w = float(SDL_GetNumberProperty(messageTexProps, SDL_PROP_TEXTURE_WIDTH_NUMBER, 0)),\n            .h = float(SDL_GetNumberProperty(messageTexProps, SDL_PROP_TEXTURE_HEIGHT_NUMBER, 0))\n    };\n\n    // init SDL Mixer\n    MIX_Mixer* mixer = MIX_CreateMixerDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, NULL);\n    if (mixer == nullptr) {\n        return SDL_Fail();\n    }\n    \n    auto mixerTrack = MIX_CreateTrack(mixer);\n\n    // load the music\n    auto musicPath = basePath / \"the_entertainer.ogg\";\n    auto music = MIX_LoadAudio(mixer,musicPath.string().c_str(),false);\n    if (not music) {\n        return SDL_Fail();\n    }\n\n    // play the music (does not loop)\n    MIX_SetTrackAudio(mixerTrack, music);\n    MIX_PlayTrack(mixerTrack, NULL);\n    \n    // print some information about the window\n    SDL_ShowWindow(window);\n    {\n        int width, height, bbwidth, bbheight;\n        SDL_GetWindowSize(window, &width, &height);\n        SDL_GetWindowSizeInPixels(window, &bbwidth, &bbheight);\n        SDL_Log(\"Window size: %ix%i\", width, height);\n        SDL_Log(\"Backbuffer size: %ix%i\", bbwidth, bbheight);\n        if (width != bbwidth){\n            SDL_Log(\"This is a highdpi environment.\");\n        }\n    }\n\n    // set up the application data\n    *appstate = new AppContext{\n       .window = window,\n       .renderer = renderer,\n       .messageTex = messageTex,\n       .imageTex = tex,\n       .messageDest = text_rect,\n       .track = mixerTrack,\n    };\n    \n    SDL_SetRenderVSync(renderer, -1);   // enable vysnc\n    \n    SDL_Log(\"Application started successfully!\");\n\n    return SDL_APP_CONTINUE;\n}\n\nSDL_AppResult SDL_AppEvent(void *appstate, SDL_Event* event) {\n    auto* app = (AppContext*)appstate;\n    \n    if (event->type == SDL_EVENT_QUIT) {\n        app->app_quit = SDL_APP_SUCCESS;\n    }\n\n    return SDL_APP_CONTINUE;\n}\n\nSDL_AppResult SDL_AppIterate(void *appstate) {\n    auto* app = (AppContext*)appstate;\n\n    // draw a color\n    auto time = SDL_GetTicks() / 1000.f;\n    auto red = (std::sin(time) + 1) / 2.0 * 255;\n    auto green = (std::sin(time / 2) + 1) / 2.0 * 255;\n    auto blue = (std::sin(time) * 2 + 1) / 2.0 * 255;\n    \n    SDL_SetRenderDrawColor(app->renderer, red, green, blue, SDL_ALPHA_OPAQUE);\n    SDL_RenderClear(app->renderer);\n\n    // Renderer uses the painter's algorithm to make the text appear above the image, we must render the image first.\n    SDL_RenderTexture(app->renderer, app->imageTex, NULL, NULL);\n    SDL_RenderTexture(app->renderer, app->messageTex, NULL, &app->messageDest);\n\n    SDL_RenderPresent(app->renderer);\n\n    return app->app_quit;\n}\n\nvoid SDL_AppQuit(void* appstate, SDL_AppResult result) {\n    auto* app = (AppContext*)appstate;\n    if (app) {\n        SDL_DestroyRenderer(app->renderer);\n        SDL_DestroyWindow(app->window);\n        \n        // prevent the music from abruptly ending.\n        MIX_StopTrack(app->track, MIX_TrackMSToFrames(app->track, 1000));\n        std::this_thread::sleep_for(std::chrono::milliseconds(1000));\n        //Mix_FreeMusic(app->music); // this call blocks until the music has finished fading\n        SDL_CloseAudioDevice(app->audioDevice);\n\n        delete app;\n    }\n    TTF_Quit();\n    MIX_Quit();\n\n    SDL_Log(\"Application quit successfully!\");\n    SDL_Quit();\n}\n"
  }
]