bool init_gl_context(struct gl_context *context, int which) { context->context = NULL; #ifdef HAVE_LINUX x11_enter_thread(); if(which == GL_CONTEXT_ANY) { printf("Trying OpenGL 3.1 first.\n"); context->context = glx_init(MK_OPENGL_VERSION(3,1)); context->legacy = FALSE; } if(!context->context) { if(which != GL_CONTEXT_LEGACY) { fprintf(stderr, "[RTDXT] OpenGL 3.1 profile failed to initialize, falling back to legacy profile.\n"); } context->context = glx_init(OPENGL_VERSION_UNSPECIFIED); context->legacy = TRUE; } if(context->context) { glx_validate(context->context); } #elif defined HAVE_MACOSX if(which == GL_CONTEXT_ANY) { if(get_mac_kernel_version_major() >= 11) { printf("[RTDXT] Mac 10.7 or latter detected. Trying OpenGL 3.2 Core profile first.\n"); context->context = mac_gl_init(MAC_GL_PROFILE_3_2); if(!context->context) { fprintf(stderr, "[RTDXT] OpenGL 3.2 Core profile failed to initialize, falling back to legacy profile.\n"); } else { context->legacy = FALSE; } } } if(!context->context) { context->context = mac_gl_init(MAC_GL_PROFILE_LEGACY); context->legacy = TRUE; } #else // WIN32 if(which == GL_CONTEXT_ANY) { context->context = win32_context_init(OPENGL_VERSION_UNSPECIFIED); } else if(which == GL_CONTEXT_LEGACY) { context->context = win32_context_init(OPENGL_VERSION_LEGACY); } context->legacy = TRUE; #endif if(context->context) { return true; } else { return false; } }
/** * @brief initializes specified OpenGL context * * @note * After this call, context is current for calling thread. * * @param[out] context newly created context * @param which OpenGL version specifier * @return info if context creation succeeded or failed */ bool init_gl_context(struct gl_context *context, int which) { context->context = NULL; #ifdef HAVE_LINUX x11_enter_thread(); if(which == GL_CONTEXT_ANY) { debug_msg("Trying OpenGL 3.1 first.\n"); context->context = glx_init(MK_OPENGL_VERSION(3,1)); context->legacy = FALSE; } if(!context->context) { if(which != GL_CONTEXT_LEGACY) { debug_msg("OpenGL 3.1 profile failed to initialize, falling back to legacy profile.\n"); } context->context = glx_init(OPENGL_VERSION_UNSPECIFIED); context->legacy = TRUE; } if(context->context) { glx_validate(context->context); } #elif defined HAVE_MACOSX if(which == GL_CONTEXT_ANY) { if(get_mac_kernel_version_major() >= 11) { debug_msg("Mac 10.7 or latter detected. Trying OpenGL 3.2 Core profile first.\n"); context->context = mac_gl_init(MAC_GL_PROFILE_3_2); if(!context->context) { debug_msg("OpenGL 3.2 Core profile failed to initialize, falling back to legacy profile.\n"); } else { context->legacy = FALSE; } } } if(!context->context) { context->context = mac_gl_init(MAC_GL_PROFILE_LEGACY); context->legacy = TRUE; } #else // WIN32 if(which == GL_CONTEXT_ANY) { context->context = win32_context_init(OPENGL_VERSION_UNSPECIFIED); } else if(which == GL_CONTEXT_LEGACY) { context->context = win32_context_init(OPENGL_VERSION_LEGACY); } context->legacy = TRUE; #endif { char *save_ptr; const char *gl_ver = (const char *) glGetString(GL_VERSION); if (!gl_ver) { fprintf(stderr, "Unable to determine OpenGL version!\n"); return false; } char *tmp = strdup(gl_ver); char *item = strtok_r(tmp, ".", &save_ptr); if (!item) { fprintf(stderr, "Unable to determine OpenGL version!\n"); free(tmp); return false; } context->gl_major = atoi(item); item = strtok_r(NULL, ".", &save_ptr); if (!item) { fprintf(stderr, "Unable to determine OpenGL version!\n"); free(tmp); return false; } context->gl_minor = atoi(item); free(tmp); } if(context->context) { return true; } else { return false; } }