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.

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

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探