2014-02-12 3 views
0

GLFW를 사용하여 Mac에서 버전 2 이상의 OpenGL 컨텍스트를 얻으려고합니다. 내 구성은 Mavericks (10.9.1) + XCode이고 Nvidia Geforce 650M GPU (OpenGL 4.1 Full Profile 포함)가 지원됩니다. 나는 다음과 같은 코드를 사용GLFW가 Mavericks에서 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 호출이 없음) 나는 OpenGL 2.1을 glsl 버전 1.20에서만 사용할 수 있습니다. 권하다.

+0

3.2가 아닌 3.3 컨텍스트를 얻을 수 있는지 궁금 할 것입니다. –

+0

오류를 반환하도록 코드를 변경했습니다. 이제 컴파일하고 4.1 ogl 컨텍스트를 생성하지만 출력 화면이 비어 있습니다! – Pourya

답변

0

#include <GLFW/glfw3.h> 앞에 추가하고 프로필 힌트의 주석 처리를 제거하십시오.

#define GLFW_INCLUDE_GLCOREARB 
+0

이제 코어 프로파일 힌트를 컴파일하지만 여전히 창을 열 수 없습니다! – Pourya

+0

Ok 올바른 버전 번호를 컴파일하고 출력하지만 화면이 공백 인 경우 : ./Split \ View OpenGL 버전 수신 : 4.1.0 지원되는 OpenGL은 4.1 NVIDIA-8.18.22 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에서 2.1보다 큰 GL 버전에 액세스하려면 핵심 컨텍스트가 필요합니다.

GLFW_OPENGL_PROFILE 힌트의 주석 처리를 제거하십시오.

관련 문제