golang-opengl
package main | |
import ( | |
"fmt" | |
"runtime" | |
"github.com/go-gl/gl/v2.1/gl" | |
"github.com/go-gl/glfw/v3.2/glfw" | |
) | |
const ( | |
windowWidth = 960 | |
windowHeight = 540 | |
) | |
func main() { | |
runtime.LockOSThread() // make sure every is called with the main thread | |
if err := glfw.Init(); err != nil { | |
panic(fmt.Errorf("Could not initialize glfw: %v", err)) | |
} | |
glfw.WindowHint(glfw.ContextVersionMajor, 4) | |
glfw.WindowHint(glfw.ContextVersionMinor, 1) | |
glfw.WindowHint(glfw.Resizable, glfw.True) | |
glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile) | |
glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True) | |
win, err := glfw.CreateWindow(windowWidth, windowHeight, "Hello world", nil, nil) | |
if err != nil { | |
panic(fmt.Errorf("Could not create opengl renderer: %v", err)) | |
} | |
win.MakeContextCurrent() | |
if err := gl.Init(); err != nil { | |
panic(err) | |
} | |
gl.ClearColor(0, 0.5, 1.0, 1.0) | |
for !win.ShouldClose() { | |
gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) | |
win.SwapBuffers() | |
glfw.PollEvents() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment