Question

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)
}
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top