
Create a simple cross-platform desktop game with Go - sausheong
https://sausheong.github.io/posts/cross-platform-games-with-go/
======
Sir_Cmpwn
I've been tinkering with writing a simple game in Golang as well. I don't
think it's a good idea to lob in an entire web browser for a game, though.
I've been using the go-gl stack:

[https://github.com/go-gl](https://github.com/go-gl)

They have a wrapper for GLFW and OpenGL, I've been using GLES2 which has good
compatability with everything. You have to be prepared to learn how to write
shaders and use OpenGL, though, so it can be a bit intimidating. Here's the
(extremely incomplete and very bad) game I have so far:

[http://git.sr.ht/~sircmpwn/freefood](http://git.sr.ht/~sircmpwn/freefood)

~~~
gameswithgo
If you are doing 2d you can also do quite well with just the SDL2 wrapper.
That gives you enough to do cross platform sound, input, and putting textures
on the screen with alpha blending and bilinear interp. So its enough to make
mario/ultima/baldurs gate/ style things.

~~~
Sir_Cmpwn
Personally I find SDL far too limiting. As soon as you want to write even one
shader you have to write all of the graphics code yourself, and at that point
it's hardly better than GLFW.

------
pravj
Wasn't aware of the mentioned "webview" wrapper[1], considering to use it for
a side project.

Reminds me of the time I created an improved version of the "8-puzzle"[1] game
in Go to learn about "channels" and "goroutines". Especially, the use of
"select" statement for listening on multiple channels for the main event loop.

[1] [https://github.com/zserge/webview](https://github.com/zserge/webview)

[2] [https://github.com/pravj/puzzl](https://github.com/pravj/puzzl)

------
akavel
See also [https://github.com/oakmound/oak](https://github.com/oakmound/oak) if
you are interested in a pure-Go library (i.e. one which doesn't need cgo) with
no HTML & JS dependencies. (Disclaimer: haven't used it so not sure what's the
status; but reportedly it's been used by its author to write a game.)

~~~
justinclift
Tried out the examples bundled with it, and for what it is it seems ok. Looks
2D only (not 3D capable), but if that's the desired target then it's probably
a decent choice. :)

------
splitbrain
Interesting, though what this actually does is run a local webserver so I
assume it would be even simpler to just open the default web browser pointed
to the local server? But then you start thinking that sound output could also
be handled via the audio API and one could even play this remotely. So what
you created is a webapp? Why even run it locally at all then... just some
thoughts. Still a cool idea to circumvent the lack of good native UI support
in go I guess.

~~~
zserge
Webview author here. It does not require local web server actually, it allows
to inject js, css, HTML in runtime and bind go structs to is objects through
the API, so the result is a self contained web app with no server. Although
using a local web server may be more convenient to most web developers.

~~~
pier25
Why IE and not Edge for Windows?

~~~
zserge
Integrating Edge is my dream. However there is no C API unlike MSHTML. I still
have hopes on cppwinrt though. Any help in this direction is highly
appreciated.

------
TeddyDD
Another good option is to use Raylib bindigs:
[https://github.com/gen2brain/raylib-go](https://github.com/gen2brain/raylib-
go)

No need for HTML/js and API is pretty simple

~~~
justinclift
Oh, this does look interesting. It mentions support for OpenGL ES 2.0, which (
_I think_ ) means it'll work with the native OpenGL drivers for the Raspberry
Pi family.

Could be a good combination for people. :)

~~~
justinclift
It turns out there are even Raspberry Pi specific examples in their docs:

[https://github.com/gen2brain/raylib-
go/tree/master/examples/...](https://github.com/gen2brain/raylib-
go/tree/master/examples/others/rpi/basic_window)

------
holografix
No mention of Ebiten?
[https://hajimehoshi.github.io/ebiten/](https://hajimehoshi.github.io/ebiten/)

------
gameswithgo
You may also enjoy: [https://gameswithgo.org/](https://gameswithgo.org/)

A video series where I teach programming via game projects. We do some
software rendering, some SDL2, simplex noise, 2d rpgs, and some 3d opengl.

------
geoka9
Not sure about game programming, but I really liked this for a portable
browser-based GUI for my Go apps:

[https://github.com/icza/gowut/wiki](https://github.com/icza/gowut/wiki)

------
justinclift
For cross platform game / 3D development in Go, there are a few frameworks and
libraries already in place:

[https://github.com/avelino/awesome-go#game-
development](https://github.com/avelino/awesome-go#game-development)

g3n seems like the most promising recent candidate:

[http://g3n.rocks](http://g3n.rocks)

[https://github.com/g3n/engine](https://github.com/g3n/engine)

Azul3D used to be a promising candidate, but looks to be very dead now. :(

~~~
gameswithgo
SDL2 + OpenGL as well

------
alienspaces
This is cool, thanks for sharing!

