From fe07c0fb6e1bb7fb2350aff8cf78f89bf8a29794 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 15 Mar 2023 07:43:47 -0500 Subject: [PATCH] misc --- main.go => android/main.go | 0 desktop/main.go | 53 ++++++++++++++++++++++++++++++++++++++ go.mod | 2 ++ go.sum | 4 +++ 4 files changed, 59 insertions(+) rename main.go => android/main.go (100%) create mode 100644 desktop/main.go diff --git a/main.go b/android/main.go similarity index 100% rename from main.go rename to android/main.go diff --git a/desktop/main.go b/desktop/main.go new file mode 100644 index 0000000..5b59360 --- /dev/null +++ b/desktop/main.go @@ -0,0 +1,53 @@ +package main + +import ( + "log" + "runtime" + + "github.com/go-gl/gl/v3.3-core/gl" + "github.com/go-gl/glfw/v3.3/glfw" +) + +const ( + width = 800 + height = 600 + title = "Go OpenGL Example" +) + +func init() { + runtime.LockOSThread() +} + +func main() { + err := glfw.Init() + if err != nil { + log.Fatalln("Failed to initialize GLFW:", err) + } + defer glfw.Terminate() + + glfw.WindowHint(glfw.ContextVersionMajor, 3) + glfw.WindowHint(glfw.ContextVersionMinor, 3) + glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile) + glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True) + + window, err := glfw.CreateWindow(width, height, title, nil, nil) + if err != nil { + log.Fatalln("Failed to create window:", err) + } + + window.MakeContextCurrent() + glfw.SwapInterval(1) + + if err := gl.Init(); err != nil { + log.Fatalln("Failed to initialize OpenGL:", err) + } + + gl.ClearColor(0.1, 0.1, 0.1, 1.0) + + for !window.ShouldClose() { + gl.Clear(gl.COLOR_BUFFER_BIT) + + window.SwapBuffers() + glfw.PollEvents() + } +} diff --git a/go.mod b/go.mod index 3892175..7727da6 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,8 @@ go 1.19 require golang.org/x/mobile v0.0.0-20230301163155-e0f57694e12c require ( + github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6 // indirect + github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b // indirect golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56 // indirect golang.org/x/image v0.0.0-20190802002840-cff245a6509b // indirect golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect diff --git a/go.sum b/go.sum index 31461df..063d201 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,8 @@ github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6 h1:zDw5v7qm4yH7N8C8uWd+8Ii9rROdgWxQuGoJ9WDXxfk= +github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6/go.mod h1:9YTyiznxEY1fVinfM7RvRcjRHbw2xLBJ3AAGIT0I4Nw= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b h1:GgabKamyOYguHqHjSkDACcgoPIz3w0Dis/zJ1wyHHHU= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56 h1:estk1glOnSVeJ9tdEZZc5mAMDZk5lNJNyJ6DvrBkTEU=