konsumer / pntr_app

Application wrapper for pntr.

Home Page:https://robloach.github.io/pntr_app/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pntr_app

Build pntr applications with the same code for a number of different targets, including SDL, raylib, libretro, the web, and more.

Features

  • Compile for a number of platforms...
  • Software rendering with pntr
  • Audio (.wav or .ogg)
  • User input...
    • Mouse
    • Keyboard
    • Gamepads

Example

#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 Event(pntr_app* app, pntr_app_event* event) {
    switch (event->type) {
        case PNTR_APP_EVENTTYPE_KEY_DOWN:
            if (event->key == PNTR_APP_KEY_SPACE) {
                // SPACE is pressed!
            }
        break;
    }
}

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,
        .event = Event,
        .close = Close,
        .fps = 60
    };
}

Configuration

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

API

pntr_app Main(int argc, char* argv[]);
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_app_userdata(pntr_app* app);
void pntr_app_set_userdata(pntr_app* app, void* userData);
int pntr_app_width(pntr_app* app);
int pntr_app_height(pntr_app* app);
float pntr_app_delta_time(pntr_app* app);
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 key);
bool pntr_app_gamepad_button_down(pntr_app* app, int gamepad, pntr_app_gamepad_button key);
bool pntr_app_gamepad_button_released(pntr_app* app, int gamepad, pntr_app_gamepad_button key);
bool pntr_app_gamepad_button_up(pntr_app* app, int gamepad, pntr_app_gamepad_button key);
int pntr_app_mouse_x(pntr_app* app);
int pntr_app_mouse_y(pntr_app* app);
int pntr_app_mouse_delta_x(pntr_app* app);
int 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);
void pntr_app_set_title(pntr_app* app, const char* title);
bool pntr_app_set_size(pntr_app* app, int width, int height);
void pntr_app_set_icon(pntr_app* app, pntr_image* icon);
void* pntr_app_file_data(pntr_app* app, unsigned int* size);
void pntr_app_log(int logLevel, const char* message);

Build

There are a few platforms supported by pntr_app, which have their own build methods...

Desktop

To build the raylib and SDL applications, use CMake. Depends on either raylib, or SDL along with SDL_mixer...

cmake -B build
cmake --build build

You can disable building some examples by using...

cmake -B build -DPNTR_APP_BUILD_EXAMPLE_SDL=false -DPNTR_APP_BUILD_EXAMPLE_RAYLIB=false
cmake --build build

libretro

To build the libretro core, use make. Depends on libretro-common.

git submodule update --init
cd example
make

libretro WASM

cd example
emmake make platform=emscripten

Web

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.html

License

Unless stated otherwise, all works are:

... and licensed under:

About

Application wrapper for pntr.

https://robloach.github.io/pntr_app/

License:zlib License


Languages

Language:C 79.3%Language:HTML 16.1%Language:CMake 4.6%Language:Perl 0.0%Language:Makefile 0.0%