veandco / go-sdl2

SDL2 binding for Go
https://godoc.org/github.com/veandco/go-sdl2
BSD 3-Clause "New" or "Revised" License
2.18k stars 219 forks source link

Need help: crosscompiling for windows (gfx colors flickering) #437

Open Linus4 opened 4 years ago

Linus4 commented 4 years ago

Hey there,

I'm developing an application that I want to port to windows. But when I cross-compile from linux, the colors of most of the shapes I draw with the gfx library are flickering or are just wrong.

Cross-compiled on windows: Video Linux: Image

Weird things I've noticed:

What I did to cross-compile:

Using Fedora 30; mingw packages for sdl image and ttf are provided by the distro (mingw64-SDL2, mingw64-SDL2_image and mingw64-SDL2_ttf); go-sdl v0.3.3

  1. download sdl2_gfx sources
  2. mingw64-configure
  3. mingw64-make
  4. sudo mingw64-make install
  5. env CGO_ENABLED="1" CC="/usr/bin/x86_64-w64-mingw32-gcc" GOOS="windows" CGO_LDFLAGS="-lmingw32 -lSDL2 -L/usr/x86_64-w64-mingw32/sys-root/mingw/lib/ -lSDL2_gfx" CGO_CFLAGS="-D_REENTRANT" go build -o csgoverview.exe -x *.go

Then I put these files into the same directory as the executable:

I have no idea where I'm going wrong - any help would be greatly appreciated :)

PS: a few demos (= replays) for testing can be found here - but any demo should work just fine

veeableful commented 4 years ago

Hi @Linus4, could you try the v0.4.0-rc.0 version and build it statically?

You can modify go.mod like this:

-       github.com/veandco/go-sdl2 v0.3.3
+       github.com/veandco/go-sdl2 v0.4.0-rc.0

and run

CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc GOOS=windows GOARCH=amd64 go build -tags static -ldflags "-s -w"

In a Windows VM I tested, it seems to not flicker. If it works for you, this could be a temporary solution!

Linus4 commented 4 years ago

Hi @veeableful , thank you so much for your help! :) Building the app statically with v0.4.0.-rc.0 works for me as well. 🎉