如何在Mac OS上的Go(Lion-10.8)中创建OpenGL 3.2上下文
I'm trying to write an OpenGL application in Go on MacOS, and can't figure out how to create a context with a version higher than OpenGL 2.1
I've tried using multiple OpenGL bindings out there, but settled on github.com/go-gl/gl
The below example will output 2.1 NVIDIA-8.12.47 310.40.00.05f01
. What do I need to do to create an OpenGL 3.2 context?
package main
import (
"fmt"
"github.com/go-gl/gl"
glfw "github.com/go-gl/glfw3"
)
func main() {
//request 3.2 context
glfw.WindowHint(glfw.ContextVersionMajor, 3)
glfw.WindowHint(glfw.ContextVersionMinor, 2)
glfw.WindowHint(glfw.OpenglProfile, glfw.OpenglCoreProfile)
if !glfw.Init() {
panic("glfw init failed")
}
defer glfw.Terminate()
//create and set window context
window, err := glfw.CreateWindow(64, 64, "foo", nil, nil)
if err != nil {
panic(err)
}
window.MakeContextCurrent()
//check version
version := gl.GetString(gl.VERSION)
fmt.Println(version)
}
我试图在Mac OS上的Go语言中编写OpenGL应用程序,但无法弄清楚如何创建 版本高于 OpenGL 2.1 strong> p>
的上下文我曾尝试使用多个OpenGL绑定,但最终选择了 github.com/go-gl / gl strong> p>
以下示例将输出 2.1 NVIDIA-8.12.47 310.40.00.05f01 code>。 创建OpenGL 3.2上下文需要做什么? p>
包main
import(
“ fmt”
“ github.com/go-gl/ gl“
glfw” github.com/go-gl/glfw3"
)
func main(){
//请求3.2上下文
glfw.WindowHint(glfw.ContextVersionMajor,3)
glfw.WindowHint( glfw.ContextVersionMinor,2)
glfw.WindowHint(glfw.OpenglProfile,glfw.OpenglCoreProfile)
如果!glfw.Init(){
panic(“ glfw init failed”)
}
延迟glfw.Terminate( )
//创建并设置窗口上下文
window,err:= glfw.CreateWindow(64,64,“ foo”,nil,nil)
如果err!= nil {
panic(err)\ n}
window.MakeContextCurrent()
//检查版本
版本:= gl.GetString(gl.VERSION)
fmt.Println(version)
}
code> pre >
div>
Since this is a C library wrapper, you might also need the equivalent of:
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
on OS X. But, more importantly, you should call glfwInit
(or it's equivalent glfw.Init
) prior to calling any other GLFW3 function. AFAIK, only glfwSetErrorCallback
can be used prior to this call.