GithubHelp home page GithubHelp logo

dafyddcrosby / go-sdl2 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from veandco/go-sdl2

0.0 3.0 0.0 1.37 MB

SDL2 binding for Go

Home Page: https://godoc.org/github.com/veandco/go-sdl2

License: BSD 3-Clause "New" or "Revised" License

Makefile 0.60% Go 98.57% C++ 0.27% Batchfile 0.24% C 0.32%

go-sdl2's Introduction

SDL2 binding for Go Build Status

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} pkg-config

On Windows,

  1. Install mingw-w64 from Mingw-builds
    - Version: latest (at time of writing 6.3.0)
    - Architecture: x86_64
    - Threads: win32
    - Exception: seh
    - Build revision: 1
    - Destination Folder: Select a folder that your Windows user owns
  2. Install SDL2 http://libsdl.org/download-2.0.php
    - Extract the SDL2 folder from the archive using a tool like 7zip
    - Inside the folder, copy the i686-w64-mingw32 and/or x86_64-w64-mingw32 depending on the architecture you chose into your mingw-w64 folder e.g. C:\Program Files\mingw-w64\x86_64-6.3.0-win32-seh-rt_v5-rev1\mingw64
  3. Setup Path environment variable
    - Put your mingw-w64 binaries location into your system Path environment variable. e.g. C:\Program Files\mingw-w64\x86_64-6.3.0-win32-seh-rt_v5-rev1\mingw64\bin and C:\Program Files\mingw-w64\x86_64-6.3.0-win32-seh-rt_v5-rev1\mingw64\x86_64-w64-mingw32\bin
  4. Open up a terminal such as Git Bash and run go get -v github.com/veandco/go-sdl2/sdl. To prove that it's working correctly, you can change directory by running cd go/src/github.com/veandco/go-sdl2/examples/events and run go run events.go. A window should pop up and you can see event logs printed when moving your mouse over it or typing on your keyboard.
  5. (Optional) You can repeat Step 2 for SDL_image, SDL_mixer, SDL_ttf
    - NOTE: pre-build the libraries for faster compilation by running go install github.com/veandco/go-sdl2/{sdl,img,mix,ttf}

or you can install SDL2 via Msys2 like so: pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-SDL2{,_mixer,_image,_ttf}

Installation

To get the bindings, type:
go get -v github.com/veandco/go-sdl2/sdl
go get -v github.com/veandco/go-sdl2/mix
go get -v github.com/veandco/go-sdl2/img
go get -v github.com/veandco/go-sdl2/ttf

or type this if you use Bash terminal:
go get -v github.com/veandco/go-sdl2/{sdl,mix,img,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() {
	if err := sdl.Init(sdl.INIT_EVERYTHING); err != nil {
		panic(err)
	}
	defer sdl.Quit()

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

	surface, err := window.GetSurface()
	if err != nil {
		panic(err)
	}

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

	sdl.Delay(2500)
}

For more complete examples, see inside the examples folder. Run any of the .go files with go run.

FAQ

Why does my program exits with code 3221225781 on Windows?
You need to put the SDL2.dll in the same folder as your program.

Why does my program crash randomly or hang?
Putting runtime.LockOSThread() at the start of your main() usually solves the problem (see SDL2 FAQ about multi-threading).

UPDATE: Recent update added a call queue system where you can put thread-sensitive code and have it called synchronously on the same OS thread. See the render_queue or render_goroutines examples to see how it works.

Why can't SDL_mixer seem to play MP3 audio file?
Your installed SDL_mixer probably doesn't support MP3 file.

On Mac OS X, this is easy to correct. First remove the faulty mixer: brew remove sdl2_mixer, then reinstall it with the MP3 option: brew install sdl2_mixer --with-flac --with-fluid-synth --with-libmikmod --with-libmodplug --with-smpeg2. If necessary, check which options you can enable with brew info sdl2_mixer.

On Other Operating Systems, you will need to compile smpeg and SDL_mixer from source with the MP3 option enabled. You can find smpeg in the external directory of SDL_mixer. Refer to issue #148 for instructions.

Does go-sdl2 support compiling on mobile platforms like Android and iOS?
For Android, see https://github.com/gen2brain/go-sdl2-android-example.

There is currently no support for iOS yet.

How do I contribute?
You can contribute by a lot of ways from improving README, fixing typos, coding style, specific bugs, performance optimizations. However, it is preferred that you break up your commits to single logical change using git add -p so it is easier to review the patch. The larger the change, the more necessary it is for the commit to be broken up to tiny little pieces. If your change is large but consistent throughout (e.g. fixing a specific coding style that happens on almost every file), that can be counted as single logical change.

You can generally start by forking the repository, and then sending pull requests. But unfortunately this is a Go project, and the absolute import statements make forking a bit more complicated. Here are some instructions, how you can work with that. Generally pull requests are very welcome.

Last but not least, we're starting to use commit messages that looks like this: sdl: fixed some typos in render.go or examples: render_goroutine: fixed a dereferenced nil pointer where it starts with folder hierarchy. It's not something strictly required but we would prefer it to be followed.

License

Go-SDL2 is BSD 3-clause licensed.

go-sdl2's People

Contributors

akovaski avatar andreas-jonsson avatar baskerville avatar bbigras avatar cdelorme avatar emlai avatar gcatlin avatar gen2brain avatar gerow avatar iand avatar jalan avatar jantuitman avatar jubalh avatar julien avatar krux02 avatar marcusva avatar moonwatcher582 avatar morcmarc avatar nightlyone avatar nlordell avatar phicode avatar r41d avatar rasky avatar slowfrog avatar stantheman avatar tanema avatar thundergroove avatar veeableful avatar whyrusleeping avatar zeroxlr avatar

Watchers

 avatar  avatar  avatar

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.