1

我正在尝试在 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() {
    //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)
}
4

1 回答 1

3

由于这是一个 C 库包装器,您可能还需要以下等价物:

glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);

在 OS X 上。但是,更重要的是,您应该在调用任何其他GLFW3 函数之前调用glfwInit(或等效的)。AFAIK,只能在此调用之前使用。glfw.InitglfwSetErrorCallback

于 2013-09-24T05:54:12.820 回答