Skip to content

Instantly share code, notes, and snippets.

@jakelacey2012
Created September 15, 2017 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakelacey2012/23bf2994c767f2f784095fd6625917d3 to your computer and use it in GitHub Desktop.
Save jakelacey2012/23bf2994c767f2f784095fd6625917d3 to your computer and use it in GitHub Desktop.
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