Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/timo/sdl2_raw-p6
Low-level NativeCall binding to SDL2
https://github.com/timo/sdl2_raw-p6
graphics-library perl6 perl6-module sdl2
Last synced: 8 days ago
JSON representation
Low-level NativeCall binding to SDL2
- Host: GitHub
- URL: https://github.com/timo/sdl2_raw-p6
- Owner: timo
- License: artistic-2.0
- Created: 2014-10-29T18:04:28.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2022-08-12T20:13:42.000Z (about 2 years ago)
- Last Synced: 2024-09-22T21:30:53.585Z (13 days ago)
- Topics: graphics-library, perl6, perl6-module, sdl2
- Language: Raku
- Size: 155 KB
- Stars: 12
- Watchers: 3
- Forks: 10
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: Changes
- License: LICENSE
Awesome Lists containing this project
README
# SDL2::Raw
[![Build Status](https://travis-ci.org/timo/SDL2_raw-p6.svg?branch=master)](https://travis-ci.org/timo/SDL2_raw-p6) [![Build status](https://ci.appveyor.com/api/projects/status/github/timo/SDL2_raw-p6?svg=true)](https://ci.appveyor.com/project/timo/SDL2_raw-p6/branch/master)
A low-sugar binding to SDL2.
## Synopsis
```perl6
use SDL2::Raw;die "couldn't initialize SDL2: { SDL_GetError }"
if SDL_Init(VIDEO) != 0;my $window = SDL_CreateWindow(
"Hello, world!",
SDL_WINDOWPOS_CENTERED_MASK, SDL_WINDOWPOS_CENTERED_MASK,
800, 600,
OPENGL
);
my $render = SDL_CreateRenderer($window, -1, ACCELERATED +| PRESENTVSYNC);my $event = SDL_Event.new;
main: loop {
SDL_SetRenderDrawColor($render, 0, 0, 0, 0);
SDL_RenderClear($render);while SDL_PollEvent($event) {
if $event.type == QUIT {
last main;
}
}SDL_SetRenderDrawColor($render, 255, 255, 255, 255);
SDL_RenderFillRect($render,
SDL_Rect.new(
2 * min(now * 300 % 800, -now * 300 % 800),
2 * min(now * 470 % 600, -now * 470 % 600),
sin(3 * now) * 50 + 80, cos(4 * now) * 50 + 60));SDL_RenderPresent($render);
}
SDL_Quit;
```## Status
There's a bunch of functions and structs already covered, but there's also a whole bunch of things I haven't touched at all. If you need any specific part of the API covered, feel free to open a ticket on github or even a pull request!
## Installation
|Platform|Installation|
|-|-|
|Ubuntu 14.04 and above|`sudo apt install libsdl2-dev`|
|Fedora 25 and above|`yum install SDL2-devel`|
|Arch Linux|`pacman -S sdl2`|
|Gentoo|`emerge -av libsdl2`|
|macOS|`brew install sdl2 pkg-config`|
|Windows|https://libsdl.org/download-2.0.php|## Examples
### Snake
![screenshots/snake-screenshot.png](screenshots/snake-screenshot.png)
A simple Snake game. Control it with the arrow keys, guide your snake to eat the red circles, and avoid running into your tail.
This code uses `Cairo` to create the images for the snake's body and tail.
### Particles
![screenshots/particles-screenshot.png](screenshots/particles-screenshot.png)
A very simple particle system that spews white pixels from a central point that get pulled down by gravity and bounce on the floor.
### Shooter
![screenshots/shooter-screenshot.png](screenshots/shooter-screenshot.png)
A more complicated game. Control it with the arrow keys and hold the spacebar to fire.
The code also uses `Cairo` to render the player's spaceship and the enemy spaceships. In generating the starfields it shows how to render to a texture with `SDL2`.
### White Noise
Just draws random white and black pixels to a texture and displays it.
![screenshots/white-noise-screenshot.png](screenshots/white-noise-screenshot.png)