Sir_Cmpwn 6 years ago

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

  • gameswithgo 6 years ago

    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 6 years ago

      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 6 years ago

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

akavel 6 years ago

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

  • justinclift 6 years ago

    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 6 years ago

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 6 years ago

    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.

    • sausheong 6 years ago

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

    • pier25 6 years ago

      Why IE and not Edge for Windows?

      • zserge 6 years ago

        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.

  • messe 6 years ago

    > Why even run it locally at all then

    Latency?

TeddyDD 6 years ago

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

No need for HTML/js and API is pretty simple

gameswithgo 6 years ago

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.

alienspaces 6 years ago

This is cool, thanks for sharing!