faiface / pixel

A hand-crafted 2D game library in Go
MIT License
4.46k stars 245 forks source link

Apple Silicon (M1+) Macs Require GLFW for OpenGL ES Implementation #304

Closed jnorrid closed 2 years ago

jnorrid commented 2 years ago

Pixel works great on AMD64-based Macs, but when I move code and rebuild on an M1 Air, I noticed a peculiar error at program startup:

2022/01/16 12:29:42 PlatformError: Cocoa: Failed to find service port for display

I figured this was an issue below Pixel so I took a look at the docs for https://github.com/go-gl/glfw

In the section about OpenGL ES, I noted this...

"If your target system only provides an OpenGL ES implementation (true for some ARM boards), you need to link against that implementation. You do this by defining the appropriate build tags, e.g.

go get -u -tags=gles2 github.com/go-gl/glfw/v3.3/glfw Supported tags are gles1, gles2, gles3 and vulkan. Note that required packages might differ from those listed above; consult your hardware's documentation."

At the command line I issued the following to correct the problem for M1 Macs:

go get -u -tags=gles3 github.com/go-gl/glfw/v3.3/glfw

So it appears that M1s implement Open GL ES 3 as I no longer get the error above.

Any way to fix this and selectively pull down the correct GLFW tag based on OpenGL implementation for that platform?

cebarks commented 2 years ago

So the solution was to add the gles3 tags to your go get command?

jnorrid commented 2 years ago

Correct.

After encountering the error with all dependencies installed and having performed a go mod tidy, I then issued:

go get -u -tags=gles3 github.com/go-gl/glfw/v3.3/glfw

The module was updated to the proper tag (gles3) for my system and then the issue went away.