Last active
September 20, 2021 01:34
-
-
Save decitrig/b4b4ad8ab71515f39b18857093556534 to your computer and use it in GitHub Desktop.
Failed attempt to cross-compile opengl, sdl, go.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
// Compile on WSL with | |
// CC=i686-w64-mingw32-gcc GOOS=windows GOARCH=386 CGO_ENABLED=1 go run . | |
import ( | |
"log" | |
"github.com/go-gl/gl/v3.3-core/gl" | |
"github.com/veandco/go-sdl2/sdl" | |
) | |
func main() { | |
if err := sdl.Init(sdl.INIT_EVERYTHING); err != nil { | |
log.Fatal("Failed to init SDL: ", err) | |
} | |
defer func() { | |
sdl.Quit() | |
}() | |
sdl.GLSetAttribute(sdl.GL_CONTEXT_PROFILE_MASK, sdl.GL_CONTEXT_PROFILE_CORE) | |
sdl.GLSetAttribute(sdl.GL_CONTEXT_MAJOR_VERSION, 3) | |
sdl.GLSetAttribute(sdl.GL_CONTEXT_MINOR_VERSION, 3) | |
win, err := sdl.CreateWindow("A window from beyond...", sdl.WINDOWPOS_CENTERED, sdl.WINDOWPOS_CENTERED, 1024, 768, sdl.WINDOW_OPENGL) | |
if err != nil { | |
log.Fatal("Failed to create window: ", err) | |
} | |
defer func() { | |
if err := win.Destroy(); err != nil { | |
log.Print("Failed to destroy window: ", err) | |
} | |
}() | |
glctx, err := win.GLCreateContext() | |
if err != nil { | |
log.Fatal("Failed to creat gl context: ", err) | |
} | |
defer sdl.GLDeleteContext(glctx) | |
gl.ClearColor(0, 0.1, 0, 1.0) | |
gl.Clear(gl.COLOR_BUFFER_BIT) | |
if err := gl.Init(); err != nil { | |
log.Fatal("Failed to init OpenGL: ", err) | |
} | |
running := true | |
for running { | |
event := sdl.PollEvent() | |
if event == nil { | |
continue | |
} | |
switch event.(type) { | |
case *sdl.QuitEvent, *sdl.KeyboardEvent: | |
running = false | |
} | |
win.GLSwap() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment