Giter Site home page Giter Site logo

sdl2_raw-p6's Introduction

SDL2::Raw

Build Status Build status

A low-sugar binding to SDL2.

Synopsis

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

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

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

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

sdl2_raw-p6's People

Contributors

azawawi avatar niner avatar pauroquero avatar samcv avatar timo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

sdl2_raw-p6's Issues

Lack of function

Please add sub SDL_DestroyWindow(SDL_Window $win) is native($lib) is export {*}
and return value to existing functions like SDL_Init etc.

factor out framerate info from examples

I'm not entirely sure if it should go into SDL2::Raw at all, but it'd surely be better to have a little module than to have it spread out over all the examples.

Currently in the "main loop" of the examples there's a native num array where frame times (taken using nqp::time_n, though surely a higher-level function ought to be okay, too, nowadays) are pushed, then at the end they are sorted and a few percentiles are printed out. However, if there's not enough values, sometimes it'll output Any or Nil or so.

It'd be nice to analyze it more thoroughly, like giving information about framerate stability (for example, how often do GC pauses increase frame times?)

Lacks a license

As far as I can tell, this module does not have a license attached to it. It would be nice to get a license for this module :) (e.g.: Artistic License v2.0, which Perl6 uses)

Build overview of missing functions, constants, and structs

It'd be cool to do this in an automated way. Either pull functions from the sdl wiki, or pull it from sdl's hg repository (both on libsdl.net)

http://wiki.libsdl.org/CategoryAPI — this has all the symbols in it, i.e. functions, constants, structs. Would be necessary to differentiate them by type, but it could be a good starting point.
http://wiki.libsdl.org/APIByCategory — this is the page i use most often to figure stuff out, for example when i want to build an example or program, rather than just to add to the bindings
https://hg.libsdl.org/SDL/file/default — this lets you browse the files of SDL's mercurial ("hg") repo

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.