SDL2 bindings for the Alusus Programming Language, providing comprehensive access to SDL2 graphics, audio, and input functionality with full Arabic language support.
- Graphics: Window creation, rendering, textures, surfaces, and 2D drawing primitives
- Audio: Music playback and sound effects via SDL2_mixer
- Input: Keyboard, mouse, and joystick/gamepad support
- Image Loading: PNG, JPG, TIF, and WEBP format support via SDL2_image
- Text Rendering: Advanced text rendering with HarfBuzz integration for proper Arabic text shaping (Linux only)
- Bilingual API: Full Arabic language bindings alongside English API
- Cross-Platform: Support for Linux and macOS
This library provides bindings for:
- SDL2: Core graphics, windowing, and event handling
- SDL2_image: Image file loading (PNG, JPG, WEBP, TIF)
- SDL2_mixer: Audio playback (music and sound effects)
- SDL2_gfx: Advanced 2D drawing primitives
- HarfBuzz Extension: Custom text rendering with proper Arabic text shaping
sudo apt-get install libsdl2-2.0-0 libsdl2-image-2.0-0 libsdl2-mixer-2.0-0 libsdl2-gfx-1.0-0brew install sdl2 sdl2_image sdl2_mixer sdl2_gfx- Alusus compiler version 0.8 or later
- Installation instructions available at alusus.org
Using Alusus Package Manager (APM):
import "Apm.alusus";
Apm.importPackage("Alusus/Sdl2@0.1", "Sdl.alusus");
import "Srl/Console.alusus";
import "Apm.alusus";
Apm.importPackage("Alusus/Sdl2@0.1", "Sdl.alusus");
// Initialize SDL
Sdl.init(Sdl.INIT_VIDEO);
// Create window
def window: ptr[Sdl.Window] = Sdl.Window.create("My Game", 0, 0, 800, 600, 0);
// Create renderer
def renderer: ptr[Sdl.Renderer] = Sdl.Renderer.create(window, -1, Sdl.Renderer.Flags.ACCELERATED);
// Main loop
def running: Bool = true;
def event: Sdl.Event;
while running {
// Handle events
while Sdl.pollEvent(event~ptr) != 0 {
if event.eventType == Sdl.Event.QUIT {
running = false;
}
}
// Clear screen
Sdl.Renderer.setDrawColor(renderer, 0, 0, 0, 255);
Sdl.Renderer.clear(renderer);
// Present frame
Sdl.Renderer.present(renderer);
}
// Initialize image subsystem
Sdl.Img.init(Sdl.Img.INIT_PNG);
// Load texture
def texture: ptr[Sdl.Texture] = Sdl.Img.loadTexture(renderer, "image.png");
// Render texture
def destRect: Sdl.Rect(100, 100, 200, 200);
Sdl.Renderer.copy(renderer, texture, 0, destRect~ptr);
// Initialize audio
Sdl.Audio.init(44100, Sdl.Audio.Format.DEFAULT, 2, 2048);
// Load and play music
def music: ptr[Sdl.Audio.Music] = Sdl.Audio.loadMusic("song.ogg");
Sdl.Audio.play(music, -1); // -1 = loop forever
// Load and play sound effect
def sound: ptr[Sdl.Audio.Sound] = Sdl.Audio.loadWav("effect.wav");
Sdl.Audio.play(-1, sound, 0, -1); // Play on first available channel
// Initialize text subsystem
Sdl.Text.init();
// Open font
def font: ptr[Sdl.Text.Font] = Sdl.Text.openFont("font.ttf", 24);
// Render text
def color: Sdl.Color(255, 255, 255, 255);
Sdl.Text.renderText("Hello, World!", color~ptr, font, 0, 100, 100, renderer);
// For Arabic text with proper shaping
Sdl.Text.renderText("مرحبا بالعالم", color~ptr, font, 1, 100, 100, renderer);
// Get keyboard state
def keyStates: ptr[array[Word[8]]] = Sdl.Keyboard.getState(0);
// Check specific keys
if keyStates~cnt(Sdl.Keyboard.ScanCode.SPACE) != 0 {
Console.print("Space pressed\n");
}
// Get mouse state
def x: Int;
def y: Int;
def buttons: Word = Sdl.Mouse.getState(x~ptr, y~ptr);
The Examples/ directory contains sample programs:
- ship.alusus: Complete game demo with graphics, audio, text rendering, and keyboard input
- joystick_test.alusus: Joystick/gamepad input demonstration
To run an example:
alusus Examples/ship.alusus- Full functionality including HarfBuzz text rendering
- Text rendering supports both LTR (English) and RTL (Arabic) scripts
- Graphics, audio, and input fully supported
- HarfBuzz text rendering is disabled on macOS
Sdl.INIT_VIDEO: Initialize video subsystemSdl.INIT_AUDIO: Initialize audio subsystemSdl.INIT_JOYSTICK: Initialize joystick subsystem
Sdl.Event.QUIT: Window close eventSdl.Event.KEY_DOWN: Key press eventSdl.Event.KEY_UP: Key release eventSdl.Event.MOUSEMOTION: Mouse movementSdl.Event.MOUSEBUTTONDOWN: Mouse button pressSdl.Event.MOUSEBUTTONUP: Mouse button release
Sdl.Renderer.Flags.SOFTWARE: Software renderingSdl.Renderer.Flags.ACCELERATED: Hardware-accelerated rendering
Sdl.BlendMode.NONE: No blendingSdl.BlendMode.BLEND: Alpha blendingSdl.BlendMode.ADD: Additive blendingSdl.BlendMode.MOD: Modulative blending
This library is licensed under the GNU Lesser General Public License (LGPL). See the COPYING and COPYING.LESSER files for details.
Contributions are welcome! Please submit issues and pull requests on the project repository.