Build pntr applications with the same code for a number of different targets, including SDL, raylib, libretro, the web, and more.
- Compile for a number of platforms...
- Software rendering with pntr
- Audio (.wav or .ogg)
- Input with Mouse, Keyboard, or Gamepads
#define PNTR_APP_IMPLEMENTATION
#include "pntr_app.h"
bool Init(pntr_app* app) {
// Initialize the application, return false on failure.
return true;
}
bool Update(pntr_app* app, pntr_image* screen) {
// Clear the screen.
pntr_clear_background(screen, PNTR_WHITE);
// Draw a circle.
pntr_draw_circle_fill(screen, screen->width / 2, screen->height / 2, 100, PNTR_BLUE);
// Continue running the application.
return true;
}
void Close(pntr_app* app) {
// Uninitialize the application.
}
pntr_app Main(int argc, char* argv[]) {
return (pntr_app) {
.width = 800,
.height = 450,
.title = "pntr_app",
.init = Init,
.update = Update,
.close = Close,
.fps = 60
};
}When compiling, define one of the following to determine which platform you are targeting...
PNTR_APP_SDL
PNTR_APP_RAYLIB
PNTR_APP_LIBRETRO
PNTR_APP_CLI
PNTR_APP_WEB
PNTR_APP_ESP32
For rendering, see the pntr API.
// Application
pntr_app Main(int argc, char* argv[]);
int pntr_app_width(pntr_app* app);
int pntr_app_height(pntr_app* app);
void pntr_app_set_title(pntr_app* app, const char* title);
const char* pntr_app_title(pntr_app* app);
void* pntr_app_userdata(pntr_app* app);
void pntr_app_set_userdata(pntr_app* app, void* userData);
bool pntr_app_set_size(pntr_app* app, int width, int height);
void pntr_app_set_icon(pntr_app* app, pntr_image* icon);
float pntr_app_delta_time(pntr_app* app);
int pntr_app_fps(pntr_app* app);
void pntr_app_set_clipboard(pntr_app* app, const char* text, int len);
const char* pntr_app_clipboard(pntr_app* app);
// Input
bool pntr_app_key_pressed(pntr_app* app, pntr_app_key key);
bool pntr_app_key_down(pntr_app* app, pntr_app_key key);
bool pntr_app_key_released(pntr_app* app, pntr_app_key key);
bool pntr_app_key_up(pntr_app* app, pntr_app_key key);
bool pntr_app_gamepad_button_pressed(pntr_app* app, int gamepad, pntr_app_gamepad_button button);
bool pntr_app_gamepad_button_down(pntr_app* app, int gamepad, pntr_app_gamepad_button button);
bool pntr_app_gamepad_button_released(pntr_app* app, int gamepad, pntr_app_gamepad_button button);
float pntr_app_mouse_x(pntr_app* app);
float pntr_app_mouse_y(pntr_app* app);
float pntr_app_mouse_delta_x(pntr_app* app);
float pntr_app_mouse_delta_y(pntr_app* app);
bool pntr_app_mouse_button_pressed(pntr_app* app, pntr_app_mouse_button button);
bool pntr_app_mouse_button_down(pntr_app* app, pntr_app_mouse_button button);
bool pntr_app_mouse_button_released(pntr_app* app, pntr_app_mouse_button button);
bool pntr_app_mouse_button_up(pntr_app* app, pntr_app_mouse_button button);
int pntr_app_mouse_wheel(pntr_app* app);
bool pntr_app_show_mouse(pntr_app* app, bool toggle);
// Utility
int pntr_app_random(pntr_app* app, int min, int max);
float pntr_app_random_float(pntr_app* app, float min, float max);
uint64_t pntr_app_random_seed(pntr_app* app);
void pntr_app_random_set_seed(pntr_app* app, uint64_t seed);
void pntr_app_log(pntr_app_log_type type, const char* message);
void pntr_app_log_ex(pntr_app_log_type type, const char* message, ...);
void* pntr_app_load_arg_file(pntr_app* app, unsigned int* size);
// Sounds
pntr_sound* pntr_load_sound(const char* fileName);
pntr_sound* pntr_load_sound_from_memory(pntr_app_sound_type type, unsigned char* data, unsigned int dataSize);
void pntr_unload_sound(pntr_sound* sound);
void pntr_play_sound(pntr_sound* sound, bool loop);
void pntr_stop_sound(pntr_sound* sound);
void pntr_set_volume(pntr_sound* sound, float volume);
bool pntr_sound_playing(pntr_sound* sound);
pntr_app_sound_type pntr_app_get_file_sound_type(const char* fileName);There are a few platforms supported by pntr_app, which have their own build methods...
To build the raylib and SDL applications, use CMake. Depends on either raylib, or SDL along with SDL_mixer...
cmake -B build
cmake --build buildYou can disable building some examples by using...
cmake -B build -DPNTR_APP_BUILD_EXAMPLE_SDL=false -DPNTR_APP_BUILD_EXAMPLE_RAYLIB=false
cmake --build buildBuild for an ESP32 with an SPI display using PlatformIO. The default board profile is the ESP32-2432S028R "Cheap Yellow Display".
cd example/esp32
pio run -e cyd -t upload -t monitorKeep the screen small. pntr allocates it as one contiguous RGBA8888 buffer, and a board
without PSRAM cannot hand out 320x240x4 bytes in one block, so declare something like
160x120 in Main() and let the platform upscale it onto the panel.
Define PNTR_APP_ESP32_SD to mount a microSD card and point pntr_load_file() and
pntr_save_file() at it. See example/esp32 for the details.
Build for the web with Emscripten and raylib. Depends on emsdk.
emcmake cmake -B build -DPNTR_APP_BUILD_EXAMPLE_RAYLIB=false -DPNTR_APP_BUILD_EXAMPLE_WEB=true
emmake make -C build
emrun build/example/index.htmlUnless stated otherwise, all works are:
- Copyright (c) 2023 Rob Loach
... and licensed under:
The vendored third-party headers in include/external/ keep their own licences, which are listed in include/external/README.md.