【问题标题】:Using OpenGL 3.2 with Derelict3 and GLFW 3 on OSX Lion在 OSX Lion 上使用 OpenGL 3.2 和 Derelict3 和 GLFW 3
【发布时间】:2012-06-03 10:43:22
【问题描述】:

我无法使用 Derelict3 和 GLFW 3 在 Lion (osx 10.7.4) 上运行 OpenGL 3.2。

这是我的测试程序:

module glfw3Test;

import std.stdio, std.conv;
import derelict.glfw3.glfw3;
import derelict.opengl3.gl3;

string programName = "glfw3Test";
int width = 640;
int height = 480;

GLFWwindow window;

void main() {
    // load opengl
    DerelictGL3.load();
    // load GLFW
    DerelictGLFW3.load();

    if(!glfwInit()) {
        glfwTerminate();
        throw new Exception("Failed to create glcontext");
    }

    writefln("GLFW:     %s", to!string(glfwGetVersionString()));

    window = glfwOpenWindow(width, height, GLFW_WINDOWED, programName.ptr, null);
    if(!window) {
        glfwTerminate();
        throw new Exception("Failed to create window");
    }

    // Request opengl 3.2 context
    // based off the GLFW FAQ: http://www.glfw.org/faq.html#4_2
    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
    glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
    glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    DerelictGL3.reload();

    // Print OpenGL and GLSL version
    writefln("Vendor:   %s",   to!string(glGetString(GL_VENDOR)));
    writefln("Renderer: %s",   to!string(glGetString(GL_RENDERER)));
    writefln("Version:  %s",   to!string(glGetString(GL_VERSION)));
    writefln("GLSL:     %s\n", to!string(glGetString(GL_SHADING_LANGUAGE_VERSION)));
}

我得到这个输出:

GLFW:     3.0.0 dynamic
Vendor:   NVIDIA Corporation
Renderer: NVIDIA GeForce 9400M OpenGL Engine
Version:  2.1 NVIDIA-7.18.18
GLSL:     1.20

我查过了,看来我的显卡应该是support up to OpenGL 3.3

【问题讨论】:

    标签: opengl osx-lion d opengl-3 glfw


    【解决方案1】:

    我所要做的就是指定一些窗口提示之前调用glfwOpenWindow:

    ...
    
    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
    glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
    
    window = glfwOpenWindow(width, height, GLFW_WINDOWED, programName.ptr, null);
    
    ...
    

    【讨论】:

      【解决方案2】:

      Lion 支持 OpenGL 3.2。您需要在代码中指定 OpenGL 3.2 核心支持

      OpenGL Profiles (Mac OS X v10.7)

      Updating an Application to Support the OpenGL 3.2 Core Specification

      【讨论】:

      • 我知道问题出在哪里。在 derelict cgl.d,代码来自 OS X 10.4。如果您使用您提供的 sn-p 运行 glfw 而没有 Derelict,您将获得正确的 OpenGL 3.2 上下文
      • 你认为这可能是我在 Lion 上编译 glfw3 的问题吗?我尝试了simple C program,我在其中指定了 GL 版本,但它无法加载窗口(错误为 The requested OpenGL version is unavailable)。
      • 目前我用CMake生成GLFW的xcode项目,然后运行$ sudo xcodebuild -sdk macosx10.7 -target install
      • 好的,我已经修好了!见我的answer above
      【解决方案3】:

      问题不在于您的显卡,而在于 OSX 视频驱动程序。 OS X 仅支持 OpenGL 2.1 和 OpenGL ES 2。 详情可咨询this table

      【讨论】:

      猜你喜欢
      • 2018-05-04
      • 2018-03-26
      • 2014-03-11
      • 2014-06-20
      • 2012-12-16
      • 1970-01-01
      • 2012-07-19
      • 1970-01-01
      • 2012-06-05
      相关资源
      最近更新 更多