On this page
  1. The example
  2. How the build tells
  3. What you keep
  4. What you give up
  5. Ads
  6. Which targets run it
  7. The smoke test
  8. The release packages

Plain C

The framework has two halves, and the second can go without the first. One is the runtime layer — rmp::, scenes, the interface, the asset pack. The other is everything around your code: the build for each target, the icons and identifiers generated from raylib_multiplatform.toml, the pinned toolchains, CI and the release. A game in plain C, with its own main() and raylib, keeps the second half and gives up the first.

The example#

examples/plain_c is that game: one C file, raylib, the framework's headers that are plain C — <rmp/config.h> and <smoke_test.h> — and a while loop of its own. Its header is the recipe and the list of what changes:

// ===========================================================================
// examples/plain_c -- the framework with none of the framework.
//
// Plain C, your own main(), raylib and nothing of ours but the CI hooks. No
// rmp::assets, no scenes, no entry-point macro. What you keep is everything
// the framework does *around* your code, which is the part that is hard to
// reproduce: the build targets, the pinned toolchains, the icons and
// identifiers generated from raylib_multiplatform.toml, the release pipeline.
//
// To use it, in a game made with `rmp new`, from the game's folder:
//
//     rm src/main.cpp && rm -r src/rmp/ src/scenes/ tests/game/
//     cp <the framework>/examples/plain_c/src/main.c src/
//     rmp run
//
// src/ is globbed by all four build systems (CMake, the Android CMakeLists,
// XcodeGen, Emscripten), so nothing else needs editing. src/rmp/ is the
// framework itself, and it goes because nothing here uses it: CMakeLists.txt
// builds the framework library from it whenever it has sources, while a src/
// with no C++ in it gets an executable linked to raylib alone -- so kept, it
// is the whole C++ framework compiled for nothing on the desktop, and
// compiled into the game on Android and iOS, whose builds take everything
// under src/. With it gone there is no framework library at all. tests/game/
// goes with src/scenes/: it tests the main menu, through the framework. Keep
// include/rmp/: this file reads [window] from <rmp/config.h>, the one header
// of ours that is plain #defines. The rmp new CI job follows the first two
// lines in a fresh game and boots what they make.
//
// What you give up, and what replaces it:
//
//   assets::Load*          ->  LoadTexture(RMP_RESOURCES_PATH "x.png"), as below
//   the resource pack      ->  gone. Loose files only: a release ships
//                              resources/ as it is, with a PACK_SKIPPED.txt
//                              saying why (tools/ship_resources.sh), because
//                              raw raylib cannot read resources.rres -- reading
//                              it is what src/rmp/assets/loader_hook.cpp was doing.
//   RMP_WINDOW_TITLE, ...  ->  #include <rmp/config.h>, as below: [window] and
//                              the rest of the .toml as plain #defines, in C.
//   the smoke-test hooks   ->  <smoke_test.h>, as below. It is C, it is on the
//                              include path, and every CI boot greps the lines it
//                              prints: a boot, a frame read back, a clean exit.
//
// TWO PLATFORMS DO NOT RUN THIS FILE AS IT STANDS, and both for the same
// reason: the `while` loop below assumes your code owns the frame loop, and on
// those two it does not.
//
//   iOS   does not call main() at all. The run loop belongs to UIKit, and
//         raylib's iOS backend calls ios_ready/ios_update/ios_destroy.
//   Web   has no loop either: the browser calls you back, through
//         emscripten_set_main_loop(). A `while` loop there freezes the tab
//         unless the whole binary is built with -s ASYNCIFY, which is a real
//         cost in size and speed and which this project does not pay.
//
// Papering over exactly that is what RMP_ENTRY_POINT is for -- it writes the
// right loop for each target and calls the same three hooks. So if you want
// iOS or Web, either keep the framework's entry point (which is one include and
// one line, and costs you nothing else) or write those two runners yourself.
// Linux, Windows, macOS, the BSDs and Android run this as it is.
// ===========================================================================

#include <raylib.h>
#include <rmp/config.h> // [window] from raylib_multiplatform.toml, as #defines
#include <smoke_test.h> // the CI hooks: no-ops unless RAY_TEST_MAX_FRAMES is set

// RMP_RESOURCES_PATH is defined by CMake, not by us: an absolute path to
// resources/ in a development build, "./resources/" in a release, "" on
// Android (where assets sit at the root of the APK). Build every asset path
// out of it and the same source works on all of them.

int main(void) {
    SmokeTest_Begin();
#if RMP_PRODUCTION_BUILD && !defined(PLATFORM_ANDROID) && !defined(__EMSCRIPTEN__)
    // A release reads "./resources/", and "." has to be the executable's folder,
    // not wherever it was started from -- a file manager, a shortcut, another
    // terminal. Only when resources/ is THERE, though: `rmp build release`
    // leaves the executable in build/ and resources/ beside build/, and run
    // from the project folder it reads that one. The framework's entry point
    // does the same for a C++ game (enter_executable_folder() in
    // src/rmp/app/app.cpp); here it is yours. GetApplicationDirectory() is "" on
    // NetBSD and OpenBSD, which cannot say where an executable is: there a
    // release reads the working directory's resources/.
    const char *folder = GetApplicationDirectory();
    if (folder[0] != '\0' &&
        DirectoryExists(TextFormat("%s%s", folder, RMP_RESOURCES_PATH))) {
        ChangeDirectory(folder);
    }
#endif
    // [window] in the .toml, the way RMP_GAME opens it: resizable, vsync if it
    // says so, and its size and title. CI checks the window was asked for the
    // vsync the .toml names.
    SetConfigFlags(RMP_WINDOW_VSYNC ? FLAG_WINDOW_RESIZABLE | FLAG_VSYNC_HINT
                                    : FLAG_WINDOW_RESIZABLE);
    InitWindow(RMP_WINDOW_WIDTH, RMP_WINDOW_HEIGHT, RMP_WINDOW_TITLE);

    Texture2D rabbit = LoadTexture(RMP_RESOURCES_PATH "rabbit.png");
    // One asset asked for, and failed if it came back empty: what the boot
    // line reports and every CI boot requires to be assets_failed=0.
    SmokeTest_ReportBoot(rabbit.id == 0 ? 1 : 0, 1);

    // The window's X ends it, and under CI so does the frame budget.
    while (!WindowShouldClose() && !SmokeTest_Done()) {
        BeginDrawing();
        ClearBackground(RAYWHITE);

        DrawTexture(rabbit, GetScreenWidth() / 2 - rabbit.width / 2,
                    GetScreenHeight() / 2 - rabbit.height / 2, WHITE);
        DrawText("Raylib is Multiplatform!", 190, 200, 20, LIGHTGRAY);

        SmokeTest_CaptureFrame(); // between the last draw and EndDrawing()
        EndDrawing();
        SmokeTest_Tick();
    }

    UnloadTexture(rabbit);
    CloseWindow();
    return 0;
}

The recipe, from the folder of a game made with rmp new:

rm src/main.cpp && rm -r src/rmp/ src/scenes/ tests/game/
cp <the framework>/examples/plain_c/src/main.c src/
rmp run

tests/game/ goes with src/scenes/: the test a new game starts with is a test of the main menu, written in C++ against the framework, and its program is built with the framework library — which a plain C game no longer has.

The framework's CI follows it on every commit, in a copy of a game freshly made with rmp new: it reads the first line out of the example and runs it, copies the file in as the second line says, and then, in place of rmp run, runs that game's render check — rmp test render — which has to build it, boot it with its one asset loaded, see a frame drawn and see it exit cleanly. Then it starts that game's release with tools/shipped_check.sh, from the project folder and from a folder with no resources/ in it, and both have to load the asset. The examples job boots the example itself like every other one.

How the build tells#

Nothing in the configuration says "this is a C game". The build looks: when the game's src/ has no .cpp file outside src/rmp/, the game is compiled as C99 and linked against raylib and nothing else — no entry point of ours, no library of ours. With src/rmp/ gone, CMake builds no framework library at all, and its configure says === NO src/rmp/: no framework library, a plain C game ===.

The recipe deletes src/rmp/, the framework's own source, because a plain C game uses none of it and the builds would compile it anyway. CMake builds the framework library from src/rmp/ whenever the folder holds sources, even while the game itself is linked to raylib alone: kept, it is the whole C++ framework compiled for nothing. Android's and iOS's builds take everything under src/, so there it would be compiled into the game itself. And a release decides by the folder what to ship in resources/: the pack while it is there, the loose files once it is gone (below).

Put a .cpp file back without src/rmp/ and the configure stops, naming the problem: … has C++ sources and there is no src/rmp/, so no framework to link …. A C++ game keeps src/rmp/, and with it the framework's entry point and library.

Both values the build defines for every game are still there: RMP_RESOURCES_PATH, the folder the files are read from — an absolute path to resources/ in a debug build, ./resources/ in a release, and empty on Android, where the files sit at the root of the APK's assets — and RMP_PRODUCTION_BUILD, 0 or 1. So is everything raylib_multiplatform.toml sets, through rmp/config.h, the one header of ours that is plain #defines: its one include is rmp/generated/config.h, the file configure.py writes from the .toml, which includes nothing. A plain C game's include path is raylib's, the game's include/, where rmp/config.h is, tests/, where smoke_test.h is, and thirdparty/raymob, where <admob.h> is (below):

int main(void) {
    InitWindow(RMP_WINDOW_WIDTH, RMP_WINDOW_HEIGHT, RMP_WINDOW_TITLE);
    while (!WindowShouldClose()) {
        BeginDrawing();
        ClearBackground(RAYWHITE);
        DrawText(RMP_PROJECT_NAME, 20, 20, 20, DARKGRAY);
        EndDrawing();
    }
    CloseWindow();
    return 0;
}

Renaming the game, or resizing its window, is still one line in one file.

What you keep#

  • The build for the targets that can run the file (below), configured from raylib_multiplatform.toml as it is for every game: rmp run, rmp build release and cmake --preset debug work the same.
  • The identifiers and the icons: the Android application id, the iOS bundle id, and the Android icons, the iOS AppIcon and the Windows .ico generated from [icon] source.
  • The version from the git tag, the pinned toolchains, CI and the release.
  • raylib itself, all of it, at the version and with the patches the framework vendors.

What you give up#

Given upWhat it means
Everything under rmp::Scenes, objects and behaviors, the interface, named input, audio by name, saves, random, and rmp::ads — though not the ads themselves (below). Your code is raylib's API and your own.
The entry pointYour main() owns the loop, which is exactly what the web and iOS do not allow (below). No [app] max_delta clamp on GetFrameTime(), and no rmp::app::quit(): the loop ends when your condition says so. Escape stays raylib's exit key and closes the window, unless your code calls SetExitKey(KEY_NULL).
Starting a release from anywhereThe framework's entry point moves a desktop release into the executable's folder when a resources/ sits next to it, so that ./resources/ is that one wherever the game was started from. In plain C that is yours, and the example does the same in a release: ChangeDirectory() into GetApplicationDirectory() only when DirectoryExists() finds resources/ there. Otherwise it stays put and reads the working directory's — which is what rmp build release needs, since it leaves the executable in build/release/ and resources/ in the project folder. On NetBSD and OpenBSD, which cannot say where an executable is, the folder is empty and the release always reads the working directory's.
The asset packReading resources.rres is the framework's runtime, and raylib alone cannot. A plain C game reads loose files only, and its release ships them — see the release packages.
The boot and render reportsThe entry point prints what CI looks for; a plain C game calls the same hooks itself. See the smoke test.

Ads#

The ads survive without rmp::. rmp::ads is a wrapper over the C functions in <admob.h>, and a plain C game has that header on its include path on every target: the real calls on Android, static inline functions that do nothing everywhere else, so the same calls compile wherever the game builds. The calls and what they mean are on the Ads page, and [android.admob] turns them on as it does for any game.

void game_over(void) {
    if (IsInterstitialAdLoaded()) ShowInterstitialAd();
    RequestInterstitialAd();
}

Which targets run it#

The file's own header says it, and the reason is the while loop: it assumes your code owns the frame loop, and on the web and iOS it does not.

TargetThe file as it stands
Windows, Linux, macOS, the BSDsRuns.
AndroidRuns, by the file's own account: raylib's Android glue calls main().
WebDoes not. The browser owns the loop and calls the game back once per frame; a while loop there needs -s ASYNCIFY, which this build deliberately does not have.
iOSDoes not. UIKit never calls main(): raylib's iOS backend calls three functions instead, and they are what the framework's entry point exists to provide.

A plain C game should say so in its configuration, so CI does not build the web and iOS, which it cannot run:

[targets]
enabled = ["all"]
disabled = ["web", "ios"]

To have the web or iOS back, keep the framework's entry point: RMP_ENTRY_POINT with three functions of yours, which writes the right loop for every target. It is C++, and that brings the rest of the framework back with it: a .cpp file in src/ needs src/rmp/, the framework's library is built and linked again, and a release ships the pack instead of the loose files — which raylib's own loaders then read through the framework. Or write those two runners yourself.

The smoke test#

CI does not take a build's word for it. It starts the game with RAY_TEST_MAX_FRAMES set, and requires three log lines: RAY_TEST_BOOT_OK with assets_failed=0, RAY_TEST_RENDER_OK for a frame read back with something on it, and RAY_TEST_DONE_FRAMES for a clean exit when the budget is spent. rmp test render asks for the same three. rmp test smoke asks for the first two only: it does not look for RAY_TEST_DONE_FRAMES.

The framework's entry point calls the hooks that print them. A plain C game calls them itself, from <smoke_test.h>, which is written to compile as C. Every hook but one does nothing unless RAY_TEST_MAX_FRAMES is set; SmokeTest_ReportBoot prints its line on every run. The example shows where each one goes:

  • SmokeTest_Begin once, first: it reads the frame budget.
  • SmokeTest_ReportBoot, with how many assets failed and how many were asked for, once the window is open and the assets are loaded. The framework counts the loads made through rmp::assets; with raylib's loaders the game counts its own, and the failed count must be 0. The line also says whether the window asked for vsync, and the render check compares that with [window] vsync — which is why the example passes FLAG_VSYNC_HINT only when RMP_WINDOW_VSYNC says so.
  • SmokeTest_CaptureFrame after the last draw call and before EndDrawing(): the frame it reads back is the one about to be shown.
  • SmokeTest_Tick after EndDrawing(), and SmokeTest_Done in the loop's condition, so that the budget ends the loop the way the window's close button does.

The release packages#

What goes in a release archive's resources/ is decided by one script, tools/ship_resources.sh, which the packaging steps of the targets that pack call — the Linux glibc and DRM ones, macOS and the BSDs — and which the windows-x64 job repeats in PowerShell. While src/rmp/ is there it ships resources.rres alone, which the framework reads. Without it, it ships the loose files of resources/, the pack left out, and a PACK_SKIPPED.txt saying that this game is plain C and raw raylib cannot read the pack. Android copies the folder into the APK whatever the game is, and the targets whose packer cannot run on the machine that builds them — Linux RISC-V, Linux musl and Windows ARM64 — ship loose files with a note of their own.