Hacker News new | past | comments | ask | show | jobs | submit login
Create a simple cross-platform desktop game with Go (sausheong.github.io)
151 points by sausheong 8 months ago | hide | past | web | favorite | 21 comments



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

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


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.


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.


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

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


See also 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.)


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. :)


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.


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.


I wrote the blog post, thanks Serge for the great library! I considered the self-contained app without the web server method, but I've already done the images before and I'm way more comfortable with Go web programming (I wrote that book too).


Why IE and not Edge for Windows?


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.


> Why even run it locally at all then

Latency?


Another good option is to use Raylib bindigs: https://github.com/gen2brain/raylib-go

No need for HTML/js and API is pretty simple


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. :)


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

https://github.com/gen2brain/raylib-go/tree/master/examples/...



You may also enjoy: 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.


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


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

g3n seems like the most promising recent candidate:

http://g3n.rocks

https://github.com/g3n/engine

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


SDL2 + OpenGL as well


This is cool, thanks for sharing!




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: