douerqu2319 2013-09-23 21:57
浏览 100
已采纳

如何在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)
}
  • 写回答

1条回答 默认 最新

  • dougan6982 2013-09-24 05:54
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!