// createContext creates an OpenGL context, binds it as the current context // stored in thread-local storage, and locks the current goroutine to an os // thread. func createContext() *contextGL { // The OpenGL active context is stored in TLS. runtime.LockOSThread() c := new(contextGL) C.CGCreate(&c.ctx) // Using attribute arrays in OpenGL 3.3 requires the use of a VBA. // But VBAs don't exist in ES 2. So we bind a default one. var id C.GLuint C.glGenVertexArrays(1, &id) C.glBindVertexArray(id) return c }
// createContext creates an OpenGL context, binds it as the current context // stored in thread-local storage, and locks the current goroutine to an os // thread. func createContext() (*contextGL, error) { // The OpenGL active context is stored in TLS. runtime.LockOSThread() c := new(contextGL) if cglErr := C.CGCreate(&c.ctx); cglErr != C.kCGLNoError { return nil, fmt.Errorf("CGL: %v", C.GoString(C.CGLErrorString(cglErr))) } // Using attribute arrays in OpenGL 3.3 requires the use of a VBA. // But VBAs don't exist in ES 2. So we bind a default one. var id C.GLuint C.glGenVertexArrays(1, &id) C.glBindVertexArray(id) return c, nil }