Skip to content
chsc edited this page Nov 10, 2012 · 1 revision

Initializing GoGL

You need to call runtime.LockOSThread() before doing any context initialization/GL drawing. Not calling this function will lead to runtime panics, because the Go scheduler will occasionally move your goroutine to a different thread. See http://code.google.com/p/go/issues/detail?id=3662 for more informations.

GLFW

Sample:

runtime.LockOSThread() // don't move the goroutine to a different thread

if err := glfw.Init(); err != nil {
    fmt.Fprintf(os.Stderr, "glfw: %s\n", err)
    return
}
defer glfw.Terminate()

glfw.OpenWindowHint(glfw.WindowNoResize, 1)

if err := glfw.OpenWindow(640, 480, 0, 0, 0, 0, 16, 0, glfw.Windowed); err != nil {
    fmt.Fprintf(os.Stderr, "glfw: %s\n", err)
    return
}
defer glfw.CloseWindow()

glfw.SetSwapInterval(1)
glfw.SetWindowTitle("GoGL")

if err := gl.Init(); err != nil { // initialize OpenGL entry points
    fmt.Fprintf(os.Stderr, "GoGL: %s\n", err)
    return
}

// use GoGL ...

Clone this wiki locally