Created
September 15, 2017 19:15
-
-
Save jakelacey2012/23bf2994c767f2f784095fd6625917d3 to your computer and use it in GitHub Desktop.
golang-opengl
This file contains hidden or 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 | |
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