These are bindings between Hare and SDL2, plus SDL satellite libraries
SDL_image
, SDL_mixer
, and SDL_ttf
. There are two modules:
sdl::v2c
exposes the raw C library and types with few modifications.sdl
wrapssdl::v2c
into idiomatic Hare.
Ditto for the satellites. The bindings are for the SDL2
branch of each
project, not the 2.0.0 release.
See the sections below for more information on each module. If you would like
additional libraries (SDL2_Pango
?), let me know! They're mostly
autogenerated, so it's not a big issue to add more.
Remember, plain SDL is almost never the right choice for making GUIs.
- Install
libsdl2
. For the examples, you will needlibsdl2-image
,libsdl2-mixer
, andlibsdl2-ttf
. - Run
make
,make info
, andmake demo
.
These are a nearly direct translation from C to Hare, with the following changes:
- C types are converted to their natural Hare counterpart,
Uint16
->u16
, etc. Of note, C'schar*
becomes*c::char
from thetypes::c
module. - Pointers that may be null have nullable added manually. I may have missed some, so feel free to fix my mistakes.
- Names that are reserved words in Hare are suffixed with an underscore.
- Opaque pointer types are replaced with opaque, no pointer. The pointer is
then added at usage sites. This allows us to make them
nullable
. - Enum value prefixes are not stripped. In C, enum values are added to the
global namespace. So from a user's perspective there is often little
difference between a #define and an enum, and the SDL library often makes the
"wrong" choice. This module directly copies SDL's choices. In Hare, as many
other languages, enum values are not added to the parent namespace. So, to
access
SDL_QUIT
in Hare, one must writeSDL_EventType::SDL_QUIT
. - Documentation and comments are not copied over. Refer to the SDL documentation.
These are wrappers over sdl::v2c
(and satellites), with the following changes:
- Function and type names are converted from
SDL_PascalCase
tosnake_case
. - enum values have their
SDL_ENUMNAME_
previx removed. char*
strings are converted to Hare strings and vice versa.- Length + pointer arrays are converted to Hare slices and vice versa.
- Sentinel-value errors are converted into Hare tagged unions.
- Documentation is brought over from SDL and adapted for Hare.
- SDL include files each get their own module. Because all of their symbols are
unique, I recommend importing all into the
sdl
scope viause sdl;
,use sdl = sdl::video;
, and so on. Then,SDL_CreateWindow
becomessdl::create_window
rather thanvideo::create_window
. Satellite libraries should be imported with their prefix,use img = sdl::image;
. - Deprecated and "don't use this" functions are omitted.
- Functions with Hare standard library equivalents are omitted.
- The
SDL_Event
tagged union is now a Hare tagged union. - Functions that use
SDL_RWops
now useio::handle
.
This wrapper is still a work-in-progress! If it is missing something that you need, please feel free to email me.