英文:
How do I create an OpenGL 3.2 context in Go on MacOS (Lion-10.8)
问题
我正在尝试在MacOS上使用Go编写一个OpenGL应用程序,但无法弄清楚如何创建一个高于OpenGL 2.1版本的上下文。
我尝试使用了多个OpenGL绑定库,但最终选择了github.com/go-gl/gl。
下面的示例将输出2.1 NVIDIA-8.12.47 310.40.00.05f01
。我需要做什么来创建一个OpenGL 3.2上下文?
package 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)
if !glfw.Init() {
panic("glfw初始化失败")
}
defer glfw.Terminate()
// 创建并设置窗口上下文
window, err := glfw.CreateWindow(64, 64, "foo", nil, nil)
if err != nil {
panic(err)
}
window.MakeContextCurrent()
// 检查版本
version := gl.GetString(gl.VERSION)
fmt.Println(version)
}
希望对你有帮助!
英文:
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)
}
答案1
得分: 3
由于这是一个C库的包装器,你可能还需要在OS X上使用以下等效代码:
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
但更重要的是,在调用任何其他GLFW3函数之前,你应该调用glfwInit
(或其等效的glfw.Init
)。据我所知,只有glfwSetErrorCallback
可以在此调用之前使用。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论