From 357e89696bad588fc715a98f522b7d6d182f082f Mon Sep 17 00:00:00 2001 From: laurentgom Date: Mon, 27 Jul 2009 16:12:49 +0000 Subject: [PATCH] Added automatic support for OpenGL 3.0 contexts on Linux git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1197 4e206d99-4929-0410-ac5d-dfc041789085 --- src/SFML/Window/Linux/ContextGLX.cpp | 36 ++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/src/SFML/Window/Linux/ContextGLX.cpp b/src/SFML/Window/Linux/ContextGLX.cpp index d176e8fe2..4e5f1eeeb 100644 --- a/src/SFML/Window/Linux/ContextGLX.cpp +++ b/src/SFML/Window/Linux/ContextGLX.cpp @@ -274,12 +274,38 @@ void ContextGLX::CreateContext(ContextGLX* shared, unsigned int bitsPerPixel, co // Get the context to share display lists with GLXContext toShare = shared ? shared->myContext : NULL; - // Create the context - myContext = glXCreateContext(myDisplay, bestVisual, toShare, true); - if (!myContext) + // Create the context -- first try an OpenGL 3.0 context if it is supported + /*const GLubyte* name = reinterpret_cast("glXCreateContextAttribsARB"); + PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = reinterpret_cast(glXGetProcAddress(name)); + if (glXCreateContextAttribsARB) { - std::cerr << "Failed to create an OpenGL context for this window" << std::endl; - return; + int nbConfigs = 0; + GLXFBConfig* configs = glXChooseFBConfig(myDisplay, DefaultScreen(myDisplay), NULL, &nbConfigs); + if (!configs || !nbConfigs) + { + std::cerr << "Failed to retrieve the framebuffer configuration" << std::endl; + return; + } + + // Create the context + int attributes[] = + { + GLX_CONTEXT_MAJOR_VERSION_ARB, 3, + GLX_CONTEXT_MINOR_VERSION_ARB, 0, + 0, 0 + }; + myContext = glXCreateContextAttribsARB(myDisplay, configs[0], toShare, true, attributes); + }*/ + + // If the OpenGL 3.0 context failed, create a regular OpenGL 1.x context + if (!myContext) + { + myContext = glXCreateContext(myDisplay, bestVisual, toShare, true); + if (!myContext) + { + std::cerr << "Failed to create an OpenGL context for this window" << std::endl; + return; + } } // Update the creation settings from the chosen format