GNU Modula-2 binding of SDL2 library.

Eric Streit 95d7773c1c feat: snake demo port with keyboard event decoding 2 semanas atrás
docs c4f2af122a docs: summary of v0.1.0 and v0.2.0 work 2 semanas atrás
examples c4aa35b7a3 feat: SDL2 bindings for GNU Modula-2, starter set 2 semanas atrás
lib 95d7773c1c feat: snake demo port with keyboard event decoding 2 semanas atrás
showcases 95d7773c1c feat: snake demo port with keyboard event decoding 2 semanas atrás
src 95d7773c1c feat: snake demo port with keyboard event decoding 2 semanas atrás
tests 95d7773c1c feat: snake demo port with keyboard event decoding 2 semanas atrás
.gitignore 2543b44389 chore: ignore vendored SDL-main sources 2 semanas atrás
Makefile 95d7773c1c feat: snake demo port with keyboard event decoding 2 semanas atrás
README.md 95d7773c1c feat: snake demo port with keyboard event decoding 2 semanas atrás

README.md

m2SDL — SDL2 bindings for GNU Modula-2

Thin DEFINITION MODULE FOR "C" bindings of SDL2 for gm2 (GCC 16 / GNU Modula-2), starting with init, video, version, timer, error and a minimal event pump.

Status

Starter set, verified with gm2 + SDL 2.32.4 on Linux:

Module C header Contents
SDL2 <SDL.h>, <SDL_error.h>, <SDL_timer.h> init/quit, GetError, Delay, ticks, performance counter
SDLVersion <SDL_version.h> SDLVersion record, GetVersion, GetRevision
SDLVideo <SDL_video.h> window create/destroy, title, size, show/hide
SDLEvents <SDL_events.h> PumpEvents, PollEvent, WaitEvent, PushEvent, quit/key/mouse type ids (opaque buffer for now)
SDLRect <SDL_rect.h> pure-M2 SDLPoint/SDLRect + helpers
SDLRender <SDL_render.h> window+renderer creation, draw color, clear/present, points/lines/rects
SDLKey <SDL_keycode.h> pure-M2 keycode constants (arrows, Q/R, Escape...)
SDLUtils (lib/) — CStrToM2() + GetErrorString() helpers, DrainEvents() quit pump, PollM2Event() decoded poll

Full SDL_Event union mapping, renderer, audio and gamepad come next.

Layout

m2SDL/
  src/        FOR "C" .def bindings (+ pure-M2 SDLRect)
  lib/        pure-M2 helpers built on the bindings (SDLUtils)
  tests/      gm2 smoke tests + run_tests.sh
  examples/   hello_window, version, event_loop
  showcases/  ports of SDL-main renderer examples (clear, rectangles, primitives)
  build/      generated binaries (git-ignored)

Prerequisites

  • gm2 (tested: 16.0.1 experimental, ~/bin/Modula2/Gm2/bin/gm2)
  • SDL2 dev files (pkg-config --cflags --libs sdl2, tested: 2.32.4)
export PATH=$HOME/bin/Modula2/Gm2/bin:$PATH

Build & test

make            # tests + examples + showcases -> build/
./tests/run_tests.sh
SDL_VIDEODRIVER=dummy ./tests/run_tests.sh   # headless
./build/examples/hello_window
./build/examples/version
./build/examples/event_loop
./build/showcases/showcase_clear   # or rectangles / primitives

make check is make tests + the runner script.

Usage

FROM SDL2 IMPORT SDL_Init, SDL_Quit, SDLInitVideo;
FROM SDLVideo IMPORT SDL_CreateWindow, SDL_DestroyWindow,
   WindowShown, WindowPosUndefined;

Compile your program with the binding search path and the C library:

gm2 -Isrc -Ilib myprog.mod src/SDLRect.mod lib/SDLUtils.mod -o myprog -lSDL2

Notes:

  • CARDINAL <-> Uint32, INTEGER <-> int (see gm2 "Elementary data types" node); opaque SDL_Window * / char * travel as ADDRESS.
  • ARRAY OF CHAR parameters map onto char *: string literals and CHAR arrays can be passed directly (see gm2 "Interface to C" node).
  • VAR record parameters map onto T *: SDL_GetVersion(v), SDL_GetWindowSize(win, w, h).

Roadmap

  1. Full SDL_Event variant record + typed poll/wait.
  2. Renderer + texture + surface subset.
  3. Audio + joystick/gamepad subset.
  4. SDL3 bindings alongside (sources at ../../SDL3-3.2.28, not yet installed).