簡體   English   中英

在Mac OS X 10.9中使用GLFW創建OpenGL 3.3上下文

[英]Creating OpenGL 3.3 Context with GLFW in Mac OS X 10.9

我有以下代碼:

void error_callback(int error, const char* description)
{
    fputs(description, stderr);
}

int main( void )
{

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

glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
//glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

// Open a window and create its OpenGL context
glfwSetErrorCallback(error_callback);
window = glfwCreateWindow( 1024, 768, "Tutorial 16 - Shadows", NULL, NULL);
if( window == NULL ){

    //fprintf( stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n" );
    glfwTerminate();
    return -1;
}
glfwMakeContextCurrent(window);

// Initialize GLEW
GLenum err;
glewExperimental = GL_TRUE; // Needed for core profile
if ((err = glewInit()) != GLEW_OK) {
    std::cout << glewGetErrorString(err) << std::endl;
    return -1;
}

...

}

問題是我收到以下消息: https : //github.com/glfw/glfw/blob/master/src/nsgl_context.m#L101

而且的確,如果不設置前向兼容標記(在Mac OS X中),GLFW不會給我OpenGL 3+上下文。

這是為什么? 有沒有辦法在Mac OS X 10.9中獲得OpenGL 3+上下文而沒有前向兼容性? 它是OS X的OpenGL實現的限制還是GLFW的問題?

實際上,這是正確的行為,如MacOpenGL編程指南中所定義。

Mac OS X根本不支持OpenGL 3.x / 4.x的兼容性配置文件,因此您必須請求一個核心(或前向兼容)上下文。 這意味着在Mac上針對OpenGL 3.x / 4.x編程時,您將無法使用任何過時的功能。

在Mac OS X上請求3.x / 4.x上下文時,可能值得在GLFW問題跟蹤器中進行功能請求以隱式設置核心配置文件標志。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM