oriont
oriont

Reputation: 762

Golang OpenGL Error PlatformError: X11: The DISPLAY environment variable is missing panic: NotInitialized: The GLFW library is not initialized

I just cannot seem to get opengl with golang to work. I wanted to try out golang but it has been such a pain to even set up, and now I can't get something I copy pasted off of this website. Here is the code I am using: (from the website). I did these two commands before running it (using wsl on windows):

go get github.com/go-gl/gl/v4.1-core/gl
go get github.com/go-gl/glfw/v3.2/glfw

And this is the full error I am getting:

2018/11/21 13:43:33 PlatformError: X11: The DISPLAY environment variable is missing
panic: NotInitialized: The GLFW library is not initialized

goroutine 1 [running, locked to thread]:
github.com/go-gl/glfw/v3.2/glfw.acceptError(0x0, 0x0, 0x0, 0x1, 0xc000099ee0)
        /home/oriont/dev/src/github.com/go-gl/glfw/v3.2/glfw/error.go:173 +0x1d1
github.com/go-gl/glfw/v3.2/glfw.panicError()
        /home/oriont/dev/src/github.com/go-gl/glfw/v3.2/glfw/error.go:184 +0x32
github.com/go-gl/glfw/v3.2/glfw.WindowHint(0x20003, 0x0)
        /home/oriont/dev/src/github.com/go-gl/glfw/v3.2/glfw/window.go:235 +0x38
main.initGlfw(0x4ded35)
        /home/oriont/dev/super g/main.go:71 +0x54
main.main()
        /home/oriont/dev/super g/main.go:45 +0x2b
exit status 2

And if you are curious, my go env:

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/oriont/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/oriont/dev"
GOPROXY=""
GORACE=""
GOROOT="/usr/lib/go-1.11"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.11/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build854283259=/tmp/go-build -gno-record-gcc-switches"

Any help would be appreciated, thanks!

EDIT:

Now I am getting a new error, after reinstalling go and removing a failed attempt at sdl2 (from apt-get remove).

(OLD) This is the new error:

# _/home/oriont/dev/super_g
/usr/lib/go-1.11/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/usr/bin/ld: cannot find -lXrandr
collect2: error: ld returned 1 exit status

I have all of the same code still. Also, I did try to run 'go build' but it just threw the exact same error as 'go run main.go'.

EDIT 2:

I reinstalled go 1.11.2 and installed the libglfw3 and libglfw3-dev packages on sudo apt-get install. Now, I have the same old error.

Upvotes: 0

Views: 3777

Answers (2)

Tiago Cavalcante
Tiago Cavalcante

Reputation: 161

For Alpine Linux the following worked:

  1. installing the following packages: apk add --no-cache mesa-dri-swrast glfw-dev mesa-dev libxcursor-dev libxrandr-dev libxinerama-dev libxi-dev
  2. exporting the variable DISPLAY as following: export DISPLAY=:0
  3. Only if you are using Docker, mounting the folder /tmp/.X11-unix (as source and target)

Upvotes: 0

oriont
oriont

Reputation: 762

My solution is to literally install GoLang and TDM-GCC on windows, and do it through the command prompt INSTEAD OF BASH.

Upvotes: -2

Related Questions