This question is a follow-up to my SO Answer about using Mesa opengl32.dll when a Golang app does not have a graphics driver to launch Fyne Windows.
I'm trying to centralize my code so that it works on any computer (Mac, Windows, Linux). Sometimes the computer already has a compatible driver and does not need the Mesa DLL to present a Fyne window, for example my MacBook runs the code great with no need for Mesa or the env variables below. However on other devices such as my Windows server I found that I need the Mesa DLL with the environment variables set inside the run.bat file.
Right now to run my code on the Windows server I have to use a run.bat file with the following content:
@echo off set GALLIUM_DRIVER=llvmpipe Main.exe pause Instead of having this extra bat file that I have to use. I am trying to add these os env variables directly from the main function but it is not working. At the start of the main function I have:
func main() { if !isOpenGLAvailable() { os.Setenv("GALLIUM_DRIVER", "llvmpipe") } // More code } func isOpenGLAvailable() bool { if err := gl.Init(); err != nil { return false } return true } How come running the bat file with these env variables works, but adding the env variables from the main function doesn't? Also is there a better way to dynamically check if the Mesa DLL is needed along with these OS env vars?
gl.Init()loads the necessary DLLs, then obviously by the time the call fails, the DLLs are already loaded so it's pointless to set the env. variables they are supposed to inspect.