2014-02-12 37 views
0

我想在使用GLFW的mac上獲得高於版本2的OpenGL上下文。我的配置是Mavericks(10.9.1)+ XCode,我有一個支持OpenGL 4.1 Full Profile的Nvidia Geforce 650M GPU。我用下面的代碼:GLFW無法在小牛上獲得OpenGL 4.1上下文

static void test_error_cb (int error, const char *description) 
{ 
    fprintf(stderr, "%d: %s\n", error, description); 
} 

INT主(無效) { GLFWwindow *窗口;

glfwSetErrorCallback(test_error_cb); 

// Initialise GLFW 
if (!glfwInit()) 
{ 
    fprintf(stderr, "Failed to initialize GLFW\n"); 
    exit(EXIT_FAILURE); 
} 


//Request Specific Version 
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); 
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); 
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); 
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); 

// Open OpenGL window 
window = glfwCreateWindow(500, 500, "Split view demo", NULL, NULL); 
if (!window) 
{ 
    fprintf(stderr, "Failed to open GLFW window\n"); 

    glfwTerminate(); 
    exit(EXIT_FAILURE); 
} 

// Set callback functions 
glfwSetFramebufferSizeCallback(window, framebufferSizeFun); 
glfwSetWindowRefreshCallback(window, windowRefreshFun); 
glfwSetCursorPosCallback(window, cursorPosFun); 
glfwSetMouseButtonCallback(window, mouseButtonFun); 
glfwSetKeyCallback(window, key_callback); 

// Enable vsync 
glfwMakeContextCurrent(window); 
glfwSwapInterval(1); 

glfwGetFramebufferSize(window, &width, &height); 
framebufferSizeFun(window, width, height); 

//Check Version 
int major, minor, rev; 
major = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MAJOR); 
minor = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MINOR); 
rev = glfwGetWindowAttrib(window, GLFW_CONTEXT_REVISION); 
printf("OpenGL version recieved: %d.%d.%d\n", major, minor, rev); 
printf("Supported OpenGL is %s\n", (const char*)glGetString(GL_VERSION)); 
printf("Supported GLSL is %s\n", (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION)); 


// Main loop 
for (;;) 
{ 
    // Only redraw if we need to 
    if (do_redraw) 
    { 
     // Draw all views 
     drawAllViews(); 

     // Swap buffers 
     glfwSwapBuffers(window); 

     do_redraw = 0; 
    } 

    // Wait for new events 
    glfwWaitEvents(); 

    // Check if the window should be closed 
    if (glfwWindowShouldClose(window)) 
     break; 
} 

// Close OpenGL window and terminate GLFW 
glfwTerminate(); 

exit(EXIT_SUCCESS); 

}

目前glfwCreateWindow功能失效。沒有任何提示(即沒有glfwWindowHint調用),我只能在1.20下使用glsl版本的OpenGL 2.1。建議。

+0

我很想知道你是否能得到3.3的上下文而不是3.2。 –

+0

現在更改了代碼以返回錯誤。現在它編譯並創建一個4.1 ogl上下文,但輸出屏幕是空白的! – Pourya

回答

0

嘗試在您的#include <GLFW/glfw3.h>之前添加此內容並取消註釋您的個人資料提示。

#define GLFW_INCLUDE_GLCOREARB 
+0

現在它編譯,但仍然與核心配置文件提示,但仍然無法打開窗口! – Pourya

+0

OK了編譯和輸出正確的版本號,但屏幕是空白: ./Split \查看 的OpenGL版本收到:4.1.0 支持的OpenGL 4.1 NVIDIA-22年8月18日310.40.05f01 支持GLSL 4.10 – Pourya

0

不確定爲什麼要禁用核心配置文件提示。我沒有答案,但你可能得到通過錯誤回調,例如一些更多的信息,

extern "C" 
{ 
    static void test_error_cb (int error, const char *description) 
    { 
     fprintf(stderr, "%d: %s\n", error, description); 
    } 
} 

... 

{ 
    glfwSetErrorCallback(test_error_cb); 

    if (glfwInit() != GL_TRUE) 
    { 
     .... 

這是一個可前glfwInit使用的功能。

1

在OSX上需要Core上下文才能訪問大於2.1的GL版本。

取消您的GLFW_OPENGL_PROFILE提示的註釋。