go-sdl2

module
v0.0.0-...-1caac2b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 28, 2014 License: BSD-3-Clause

README

SDL2 binding for Go

go-sdl2 is SDL2 wrapped for Go users. It enables interoperability between Go and the SDL2 library which is written in C. That means the original SDL2 installation is required for this to work.

Requirements

Below is some commands that can be used to install the required packages in some Linux distributions. Some older versions of the distributions such as Ubuntu 13.10 may also be used but it may miss an optional package such as libsdl2-ttf-dev on Ubuntu 13.10's case which is available in Ubuntu 14.04.

On Ubuntu 14.04 and above, type:
apt-get install libsdl2{,-mixer,-image,-ttf}-dev
Note: Ubuntu 14.04 currently has broken header file in the SDL2 package that disables people from compiling against it. It will be needed to either patch the header file or install SDL2 from source.

On Fedora 20 and above, type:
yum install SDL2{,_mixer,_image,_ttf}-devel

On Arch Linux, type:
pacman -S sdl2{,_mixer,_image,_ttf}

On Mac OS X, install SDL2 via Homebrew like so: brew install sdl2{,_image,_ttf,_mixer}

Installation

To get the bindings, type:
go get -v github.com/veandco/go-sdl2/sdl
go get -v github.com/veandco/go-sdl2/sdl_mixer
go get -v github.com/veandco/go-sdl2/sdl_image
go get -v github.com/veandco/go-sdl2/sdl_ttf

or type this if you use Bash terminal:
go get -v github.com/veandco/go-sdl2/sdl{,_mixer,_image,_ttf}

Note: If you didn't use the previous commands or use 'go install', you will experience long compilation time because Go doesn't keep the built binaries unless you install them.

Example

package main

import "github.com/veandco/go-sdl2/sdl"

func main() {
	window, err := sdl.CreateWindow("test", sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED,
		800, 600, sdl.WINDOW_SHOWN)
	if err != nil {
		panic(err)
	}

	surface := window.GetSurface()

	rect := sdl.Rect{0, 0, 200, 200}
	surface.FillRect(&rect, 0xffff0000)
	window.UpdateSurface()

	sdl.Delay(1000)
	window.Destroy()
}

For more complete examples, see inside the examples folder.

Documentation

For now, take a look at http://godoc.org/github.com/veandco/go-sdl2/sdl. A full-featured website will be created once we hit a stable point.

Notes

A standalone Go SDL2 library is being considered (read: figured out). That means users should be able to just go get go-sdl2 and compile it without the original C library. That could mean faster build times, more 'idiomatic' Go code, and hopefully more people interested in using and contributing to go-sdl2!

Contributors

License

Go-SDL2 is BSD 3-clause licensed.

Directories

Path Synopsis
testing
events
This program creates an SDL window and renderer and pushes UserEvents using PeepEvents This program creates an SDL window and renderer and takes in events using sdl.PeepEvents This program creates an SDL window and renderer and pushes events with PushEvent to be read by PollEvents This program creates an SDL window and renderer and takes in events using sdl.WaitEvent This program creates an SDL window and renderer and takes in events using sdl.WaitEventTimeout If there is a timeout (1000 ms), the program prints that there was and tries again
This program creates an SDL window and renderer and pushes UserEvents using PeepEvents This program creates an SDL window and renderer and takes in events using sdl.PeepEvents This program creates an SDL window and renderer and pushes events with PushEvent to be read by PollEvents This program creates an SDL window and renderer and takes in events using sdl.WaitEvent This program creates an SDL window and renderer and takes in events using sdl.WaitEventTimeout If there is a timeout (1000 ms), the program prints that there was and tries again

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL