diff --git a/CSFML/doc/build/Doxygen.hpp b/CSFML/doc/build/Doxygen.hpp index 17ac9f867..7f537d385 100644 --- a/CSFML/doc/build/Doxygen.hpp +++ b/CSFML/doc/build/Doxygen.hpp @@ -18,7 +18,6 @@ /// /// int main() /// { -/// sfWindowSettings settings = {24, 8, 0}; /// sfVideoMode mode = {800, 600, 32}; /// sfRenderWindow* window; /// sfImage* image; @@ -29,7 +28,7 @@ /// sfEvent event; /// /// /* Create the main window */ -/// window = sfRenderWindow_Create(mode, "SFML window", sfResize | sfClose, settings); +/// window = sfRenderWindow_Create(mode, "SFML window", sfResize | sfClose, NULL); /// if (!window) /// return EXIT_FAILURE; /// diff --git a/CSFML/include/SFML/Graphics/RenderWindow.h b/CSFML/include/SFML/Graphics/RenderWindow.h index 54235d408..45087923c 100644 --- a/CSFML/include/SFML/Graphics/RenderWindow.h +++ b/CSFML/include/SFML/Graphics/RenderWindow.h @@ -44,19 +44,19 @@ /// \param mode : Video mode to use /// \param title : Title of the window /// \param style : Window style -/// \param settings : Creation settings +/// \param settings : Creation settings (pass NULL to use default values) /// //////////////////////////////////////////////////////////// -CSFML_API sfRenderWindow* sfRenderWindow_Create(sfVideoMode mode, const char* title, unsigned long style, sfContextSettings settings); +CSFML_API sfRenderWindow* sfRenderWindow_Create(sfVideoMode mode, const char* title, unsigned long style, sfContextSettings* settings); //////////////////////////////////////////////////////////// /// Construct a renderwindow from an existing control /// /// \param handle : Platform-specific handle of the control -/// \param settings : Creation settings +/// \param settings : Creation settings (pass NULL to use default values) /// //////////////////////////////////////////////////////////// -CSFML_API sfRenderWindow* sfRenderWindow_CreateFromHandle(sfWindowHandle handle, sfContextSettings settings); +CSFML_API sfRenderWindow* sfRenderWindow_CreateFromHandle(sfWindowHandle handle, sfContextSettings* settings); //////////////////////////////////////////////////////////// /// Destroy an existing renderwindow diff --git a/CSFML/include/SFML/Window/Window.h b/CSFML/include/SFML/Window/Window.h index 064c94437..408a16a0c 100644 --- a/CSFML/include/SFML/Window/Window.h +++ b/CSFML/include/SFML/Window/Window.h @@ -57,6 +57,8 @@ typedef struct unsigned int DepthBits; ///< Bits of the depth buffer unsigned int StencilBits; ///< Bits of the stencil buffer unsigned int AntialiasingLevel; ///< Level of antialiasing + unsigned int MajorVersion; ///< Major number of the context version to create + unsigned int MinorVersion; ///< Minor number of the context version to create } sfContextSettings; @@ -66,19 +68,19 @@ typedef struct /// \param mode : Video mode to use /// \param title : Title of the window /// \param style : Window style -/// \param settings : Creation settings +/// \param settings : Creation settings (pass NULL to use default values) /// //////////////////////////////////////////////////////////// -CSFML_API sfWindow* sfWindow_Create(sfVideoMode mode, const char* title, unsigned long style, sfContextSettings settings); +CSFML_API sfWindow* sfWindow_Create(sfVideoMode mode, const char* title, unsigned long style, sfContextSettings* settings); //////////////////////////////////////////////////////////// /// Construct a window from an existing control /// /// \param handle : Platform-specific handle of the control -/// \param settings : Creation settings +/// \param settings : Creation settings (pass NULL to use default values) /// //////////////////////////////////////////////////////////// -CSFML_API sfWindow* sfWindow_CreateFromHandle(sfWindowHandle handle, sfContextSettings settings); +CSFML_API sfWindow* sfWindow_CreateFromHandle(sfWindowHandle handle, sfContextSettings* settings); //////////////////////////////////////////////////////////// /// Destroy an existing window diff --git a/CSFML/src/SFML/Graphics/RenderWindow.cpp b/CSFML/src/SFML/Graphics/RenderWindow.cpp index 544c5130d..5d3427f05 100644 --- a/CSFML/src/SFML/Graphics/RenderWindow.cpp +++ b/CSFML/src/SFML/Graphics/RenderWindow.cpp @@ -39,15 +39,25 @@ //////////////////////////////////////////////////////////// /// Construct a new renderwindow //////////////////////////////////////////////////////////// -sfRenderWindow* sfRenderWindow_Create(sfVideoMode mode, const char* title, unsigned long style, sfContextSettings params) +sfRenderWindow* sfRenderWindow_Create(sfVideoMode mode, const char* title, unsigned long style, sfContextSettings* settings) { // Convert video mode sf::VideoMode videoMode(mode.Width, mode.Height, mode.BitsPerPixel); + // Convert context settings + sf::ContextSettings params; + if (settings) + { + params.DepthBits = settings->DepthBits; + params.StencilBits = settings->StencilBits; + params.AntialiasingLevel = settings->AntialiasingLevel; + params.MajorVersion = settings->MajorVersion; + params.MinorVersion = settings->MinorVersion; + } + // Create the window sfRenderWindow* renderWindow = new sfRenderWindow; - sf::ContextSettings settings(params.DepthBits, params.StencilBits, params.AntialiasingLevel); - renderWindow->This.Create(videoMode, title, style, settings); + renderWindow->This.Create(videoMode, title, style, params); renderWindow->Input.This = &renderWindow->This.GetInput(); renderWindow->DefaultView = new sfView(const_cast(&renderWindow->This.GetDefaultView())); renderWindow->CurrentView = renderWindow->DefaultView; @@ -59,11 +69,22 @@ sfRenderWindow* sfRenderWindow_Create(sfVideoMode mode, const char* title, unsig //////////////////////////////////////////////////////////// /// Construct a renderwindow from an existing control //////////////////////////////////////////////////////////// -sfRenderWindow* sfRenderWindow_CreateFromHandle(sfWindowHandle handle, sfContextSettings params) +sfRenderWindow* sfRenderWindow_CreateFromHandle(sfWindowHandle handle, sfContextSettings* settings) { + // Convert context settings + sf::ContextSettings params; + if (settings) + { + params.DepthBits = settings->DepthBits; + params.StencilBits = settings->StencilBits; + params.AntialiasingLevel = settings->AntialiasingLevel; + params.MajorVersion = settings->MajorVersion; + params.MinorVersion = settings->MinorVersion; + } + + // Create the window sfRenderWindow* renderWindow = new sfRenderWindow; - sf::ContextSettings settings(params.DepthBits, params.StencilBits, params.AntialiasingLevel); - renderWindow->This.Create(handle, settings); + renderWindow->This.Create(handle, params); renderWindow->Input.This = &renderWindow->This.GetInput(); renderWindow->DefaultView = new sfView(const_cast(&renderWindow->This.GetDefaultView())); renderWindow->CurrentView = renderWindow->DefaultView; diff --git a/CSFML/src/SFML/Window/Window.cpp b/CSFML/src/SFML/Window/Window.cpp index d4389fbaa..a173cf97d 100644 --- a/CSFML/src/SFML/Window/Window.cpp +++ b/CSFML/src/SFML/Window/Window.cpp @@ -34,14 +34,24 @@ //////////////////////////////////////////////////////////// /// Construct a new window //////////////////////////////////////////////////////////// -sfWindow* sfWindow_Create(sfVideoMode mode, const char* title, unsigned long style, sfContextSettings settings) +sfWindow* sfWindow_Create(sfVideoMode mode, const char* title, unsigned long style, sfContextSettings* settings) { // Convert video mode sf::VideoMode videoMode(mode.Width, mode.Height, mode.BitsPerPixel); + // Convert context settings + sf::ContextSettings params; + if (settings) + { + params.DepthBits = settings->DepthBits; + params.StencilBits = settings->StencilBits; + params.AntialiasingLevel = settings->AntialiasingLevel; + params.MajorVersion = settings->MajorVersion; + params.MinorVersion = settings->MinorVersion; + } + // Create the window sfWindow* window = new sfWindow; - sf::ContextSettings params(settings.DepthBits, settings.StencilBits, settings.AntialiasingLevel); window->This.Create(videoMode, title, style, params); window->Input.This = &window->This.GetInput(); @@ -52,10 +62,21 @@ sfWindow* sfWindow_Create(sfVideoMode mode, const char* title, unsigned long sty //////////////////////////////////////////////////////////// /// Construct a window from an existing control //////////////////////////////////////////////////////////// -sfWindow* sfWindow_CreateFromHandle(sfWindowHandle handle, sfContextSettings settings) +sfWindow* sfWindow_CreateFromHandle(sfWindowHandle handle, sfContextSettings* settings) { + // Convert context settings + sf::ContextSettings params; + if (settings) + { + params.DepthBits = settings->DepthBits; + params.StencilBits = settings->StencilBits; + params.AntialiasingLevel = settings->AntialiasingLevel; + params.MajorVersion = settings->MajorVersion; + params.MinorVersion = settings->MinorVersion; + } + + // Create the window sfWindow* window = new sfWindow; - sf::ContextSettings params(settings.DepthBits, settings.StencilBits, settings.AntialiasingLevel); window->This.Create(handle, params); window->Input.This = &window->This.GetInput(); diff --git a/dotnet/extlibs/csfml-audio.dll b/dotnet/extlibs/csfml-audio.dll index aa85cc253..74200496d 100644 Binary files a/dotnet/extlibs/csfml-audio.dll and b/dotnet/extlibs/csfml-audio.dll differ diff --git a/dotnet/extlibs/csfml-graphics.dll b/dotnet/extlibs/csfml-graphics.dll index 7f3712a9e..4ec05ec38 100644 Binary files a/dotnet/extlibs/csfml-graphics.dll and b/dotnet/extlibs/csfml-graphics.dll differ diff --git a/dotnet/extlibs/csfml-window.dll b/dotnet/extlibs/csfml-window.dll index 5165ca0e8..0570f3538 100644 Binary files a/dotnet/extlibs/csfml-window.dll and b/dotnet/extlibs/csfml-window.dll differ diff --git a/dotnet/src/Graphics/RenderWindow.cs b/dotnet/src/Graphics/RenderWindow.cs index 0a454f0ac..b142838f6 100644 --- a/dotnet/src/Graphics/RenderWindow.cs +++ b/dotnet/src/Graphics/RenderWindow.cs @@ -25,7 +25,7 @@ namespace SFML /// Title of the window //////////////////////////////////////////////////////////// public RenderWindow(VideoMode mode, string title) : - this(mode, title, Styles.Resize | Styles.Close, new ContextSettings(24, 8, 0)) + this(mode, title, Styles.Resize | Styles.Close, new ContextSettings(24, 8)) { } @@ -38,7 +38,7 @@ namespace SFML /// Window style (Resize | Close by default) //////////////////////////////////////////////////////////// public RenderWindow(VideoMode mode, string title, Styles style) : - this(mode, title, style, new ContextSettings(24, 8, 0)) + this(mode, title, style, new ContextSettings(24, 8)) { } @@ -52,7 +52,7 @@ namespace SFML /// Creation parameters //////////////////////////////////////////////////////////// public RenderWindow(VideoMode mode, string title, Styles style, ContextSettings settings) : - base(sfRenderWindow_Create(mode, title, style, settings), 0) + base(sfRenderWindow_Create(mode, title, style, ref settings), 0) { Initialize(); } @@ -64,7 +64,7 @@ namespace SFML /// Platform-specific handle of the control //////////////////////////////////////////////////////////// public RenderWindow(IntPtr handle) : - this(handle, new ContextSettings(24, 8, 0)) + this(handle, new ContextSettings(24, 8)) { } @@ -76,7 +76,7 @@ namespace SFML /// Creation parameters //////////////////////////////////////////////////////////// public RenderWindow(IntPtr handle, ContextSettings settings) : - base(sfRenderWindow_CreateFromHandle(handle, settings), 0) + base(sfRenderWindow_CreateFromHandle(handle, ref settings), 0) { Initialize(); } @@ -481,10 +481,10 @@ namespace SFML #region Imports [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] - static extern IntPtr sfRenderWindow_Create(VideoMode Mode, string Title, Styles Style, ContextSettings Params); + static extern IntPtr sfRenderWindow_Create(VideoMode Mode, string Title, Styles Style, ref ContextSettings Params); [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] - static extern IntPtr sfRenderWindow_CreateFromHandle(IntPtr Handle, ContextSettings Params); + static extern IntPtr sfRenderWindow_CreateFromHandle(IntPtr Handle, ref ContextSettings Params); [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] static extern void sfRenderWindow_Destroy(IntPtr This); diff --git a/dotnet/src/Window/ContextSettings.cs b/dotnet/src/Window/ContextSettings.cs index a8c73269c..bf57baa30 100644 --- a/dotnet/src/Window/ContextSettings.cs +++ b/dotnet/src/Window/ContextSettings.cs @@ -33,11 +33,28 @@ namespace SFML /// Stencil buffer bits /// Antialiasing level //////////////////////////////////////////////////////////// - public ContextSettings(uint depthBits, uint stencilBits, uint antialiasingLevel) + public ContextSettings(uint depthBits, uint stencilBits, uint antialiasingLevel) : + this(depthBits, stencilBits, antialiasingLevel, 2, 0) + { + } + + //////////////////////////////////////////////////////////// + /// + /// Construct the settings from depth / stencil bits and antialiasing level + /// + /// Depth buffer bits + /// Stencil buffer bits + /// Antialiasing level + /// Major number of the context version + /// Minor number of the context version + //////////////////////////////////////////////////////////// + public ContextSettings(uint depthBits, uint stencilBits, uint antialiasingLevel, uint majorVersion, uint minorVersion) { DepthBits = depthBits; StencilBits = stencilBits; AntialiasingLevel = antialiasingLevel; + MajorVersion = majorVersion; + MinorVersion = minorVersion; } /// Depth buffer bits (0 is disabled) @@ -48,6 +65,12 @@ namespace SFML /// Antialiasing level (0 is disabled) public uint AntialiasingLevel; + + /// Major number of the context version + public uint MajorVersion; + + /// Minor number of the context version + public uint MinorVersion; } } } diff --git a/dotnet/src/Window/Window.cs b/dotnet/src/Window/Window.cs index 7371b7422..9fd387a8a 100644 --- a/dotnet/src/Window/Window.cs +++ b/dotnet/src/Window/Window.cs @@ -47,7 +47,7 @@ namespace SFML /// Title of the window //////////////////////////////////////////////////////////// public Window(VideoMode mode, string title) : - this(mode, title, Styles.Resize | Styles.Close, new ContextSettings(24, 8, 0)) + this(mode, title, Styles.Resize | Styles.Close, new ContextSettings(24, 8)) { } @@ -60,7 +60,7 @@ namespace SFML /// Window style (Resize | Close by default) //////////////////////////////////////////////////////////// public Window(VideoMode mode, string title, Styles style) : - this(mode, title, style, new ContextSettings(24, 8, 0)) + this(mode, title, style, new ContextSettings(24, 8)) { } @@ -74,7 +74,7 @@ namespace SFML /// Creation parameters //////////////////////////////////////////////////////////// public Window(VideoMode mode, string title, Styles style, ContextSettings settings) : - base(sfWindow_Create(mode, title, style, settings)) + base(sfWindow_Create(mode, title, style, ref settings)) { myInput = new Input(sfWindow_GetInput(This)); } @@ -86,7 +86,7 @@ namespace SFML /// Platform-specific handle of the control //////////////////////////////////////////////////////////// public Window(IntPtr handle) : - this(handle, new ContextSettings(24, 8, 0)) + this(handle, new ContextSettings(24, 8)) { } @@ -98,7 +98,7 @@ namespace SFML /// Creation parameters //////////////////////////////////////////////////////////// public Window(IntPtr Handle, ContextSettings settings) : - base(sfWindow_CreateFromHandle(Handle, settings)) + base(sfWindow_CreateFromHandle(Handle, ref settings)) { myInput = new Input(sfWindow_GetInput(This)); } @@ -155,7 +155,7 @@ namespace SFML //////////////////////////////////////////////////////////// public virtual uint Width { - get { return sfWindow_GetWidth(This); } + get {return sfWindow_GetWidth(This);} } //////////////////////////////////////////////////////////// @@ -165,7 +165,7 @@ namespace SFML //////////////////////////////////////////////////////////// public virtual uint Height { - get { return sfWindow_GetHeight(This); } + get {return sfWindow_GetHeight(This);} } //////////////////////////////////////////////////////////// @@ -175,7 +175,7 @@ namespace SFML //////////////////////////////////////////////////////////// public virtual ContextSettings Settings { - get { return sfWindow_GetSettings(This); } + get {return sfWindow_GetSettings(This);} } //////////////////////////////////////////////////////////// @@ -555,10 +555,10 @@ namespace SFML #region Imports [DllImport("csfml-window"), SuppressUnmanagedCodeSecurity] - static extern IntPtr sfWindow_Create(VideoMode Mode, string Title, Styles Style, ContextSettings Params); + static extern IntPtr sfWindow_Create(VideoMode Mode, string Title, Styles Style, ref ContextSettings Params); [DllImport("csfml-window"), SuppressUnmanagedCodeSecurity] - static extern IntPtr sfWindow_CreateFromHandle(IntPtr Handle, ContextSettings Params); + static extern IntPtr sfWindow_CreateFromHandle(IntPtr Handle, ref ContextSettings Params); [DllImport("csfml-window"), SuppressUnmanagedCodeSecurity] static extern void sfWindow_Destroy(IntPtr This); diff --git a/include/SFML/Window/ContextSettings.hpp b/include/SFML/Window/ContextSettings.hpp index 941ba917f..2ddcb89e6 100644 --- a/include/SFML/Window/ContextSettings.hpp +++ b/include/SFML/Window/ContextSettings.hpp @@ -31,6 +31,7 @@ namespace sf //////////////////////////////////////////////////////////// /// \brief Structure defining the settings of the OpenGL /// context attached to a window +/// //////////////////////////////////////////////////////////// struct ContextSettings { @@ -40,12 +41,16 @@ struct ContextSettings /// \param depth Depth buffer bits /// \param stencil Stencil buffer bits /// \param antialiasing Antialiasing level + /// \param major Major number of the context version + /// \param minor Minor number of the context version /// //////////////////////////////////////////////////////////// - explicit ContextSettings(unsigned int depth = 24, unsigned int stencil = 8, unsigned int antialiasing = 0) : + explicit ContextSettings(unsigned int depth = 24, unsigned int stencil = 8, unsigned int antialiasing = 0, unsigned int major = 2, unsigned int minor = 0) : DepthBits (depth), StencilBits (stencil), - AntialiasingLevel(antialiasing) + AntialiasingLevel(antialiasing), + MajorVersion (major), + MinorVersion (minor) { } @@ -55,9 +60,44 @@ struct ContextSettings unsigned int DepthBits; ///< Bits of the depth buffer unsigned int StencilBits; ///< Bits of the stencil buffer unsigned int AntialiasingLevel; ///< Level of antialiasing + unsigned int MajorVersion; ///< Major number of the context version to create + unsigned int MinorVersion; ///< Minor number of the context version to create }; } // namespace sf #endif // SFML_CONTEXTSETTINGS_HPP + + +//////////////////////////////////////////////////////////// +/// \class sf::ContextSettings +/// +/// ContextSettings allows to define several advanced settings +/// of the OpenGL context attached to a window. All these +/// settings have no impact on the regular SFML rendering +/// (graphics module), so you may need to use this structure +/// only if you're using SFML as a windowing system for +/// custom OpenGL rendering. +/// +/// The DepthBits and StencilBits members define the number +/// of bits per pixel requested for the (respectively) depth +/// and stencil buffers. +/// +/// AntialiasingLevel represents the requested number of +/// multisampling levels for anti-aliasing. +/// +/// MajorVersion and MinorVersion define the version of the +/// OpenGL context that you want. Only versions greater or +/// equal to 3.0 are relevant; versions lesser than 3.0 are +/// all handled the same way (i.e. you can use any version +/// < 3.0 if you don't want an OpenGL 3 context). +/// +/// Please note that these values are only a hint. +/// No failure will be reported if one or more of these values +/// are not supported by the system; instead, SFML will try to +/// find the closest valid match. You can then retrieve the +/// settings that the window actually used to create its context, +/// with Window::GetSettings(). +/// +//////////////////////////////////////////////////////////// diff --git a/src/SFML/Window/ContextGL.cpp b/src/SFML/Window/ContextGL.cpp index c8a6d09e3..156aa3e1f 100644 --- a/src/SFML/Window/ContextGL.cpp +++ b/src/SFML/Window/ContextGL.cpp @@ -152,6 +152,8 @@ bool ContextGL::SetReferenceActive() { if (threadContext) return threadContext->SetActive(true); + else + return false; } diff --git a/src/SFML/Window/Linux/ContextGLX.cpp b/src/SFML/Window/Linux/ContextGLX.cpp index 92ca7c50e..b72660d5c 100644 --- a/src/SFML/Window/Linux/ContextGLX.cpp +++ b/src/SFML/Window/Linux/ContextGLX.cpp @@ -246,30 +246,60 @@ 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 -- 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) + // Create the OpenGL context -- first try an OpenGL 3.0 context if it is requested + if (settings.MajorVersion >= 3) { - int nbConfigs = 0; - GLXFBConfig* configs = glXChooseFBConfig(myDisplay, DefaultScreen(myDisplay), NULL, &nbConfigs); - if (!configs || !nbConfigs) + PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = reinterpret_cast(wglGetProcAddress("wglCreateContextAttribsARB")); + if (wglCreateContextAttribsARB) { - std::cerr << "Failed to retrieve the framebuffer configuration" << std::endl; - return; + int attributes[] = + { + WGL_CONTEXT_MAJOR_VERSION_ARB, settings.MajorVersion, + WGL_CONTEXT_MINOR_VERSION_ARB, settings.MinorVersion, + 0, 0 + }; + myContext = wglCreateContextAttribsARB(myDeviceContext, sharedContext, attributes); } - // Create the context - int attributes[] = + // If we couldn't create an OpenGL 3 context, adjust the settings + if (!myContext) { - GLX_CONTEXT_MAJOR_VERSION_ARB, 3, - GLX_CONTEXT_MINOR_VERSION_ARB, 0, - 0, 0 - }; - myContext = glXCreateContextAttribsARB(myDisplay, configs[0], toShare, true, attributes); - }*/ + mySettings.MajorVersion = 2; + mySettings.MinorVersion = 0; + } + } - // If the OpenGL 3.0 context failed, create a regular OpenGL 1.x context + // Create the OpenGL context -- first try an OpenGL 3.0 context if it is requested + if (settings.MajorVersion >= 3) + { + const GLubyte* name = reinterpret_cast("glXCreateContextAttribsARB"); + PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = reinterpret_cast(glXGetProcAddress(name)); + if (glXCreateContextAttribsARB) + { + int nbConfigs = 0; + GLXFBConfig* configs = glXChooseFBConfig(myDisplay, DefaultScreen(myDisplay), NULL, &nbConfigs); + if (configs && nbConfigs) + { + // Create the context + int attributes[] = + { + GLX_CONTEXT_MAJOR_VERSION_ARB, settings.MajorVersion, + GLX_CONTEXT_MINOR_VERSION_ARB, settings.MinorVersion, + 0, 0 + }; + myContext = glXCreateContextAttribsARB(myDisplay, configs[0], toShare, true, attributes); + } + } + + // If we couldn't create an OpenGL 3 context, adjust the settings + if (!myContext) + { + mySettings.MajorVersion = 2; + mySettings.MinorVersion = 0; + } + } + + // If the OpenGL 3.0 context failed or if we don't want one, create a regular OpenGL 1.x/2.x context if (!myContext) { myContext = glXCreateContext(myDisplay, bestVisual, toShare, true); diff --git a/src/SFML/Window/Win32/ContextWGL.cpp b/src/SFML/Window/Win32/ContextWGL.cpp index 46a1b5eb2..ba328c236 100644 --- a/src/SFML/Window/Win32/ContextWGL.cpp +++ b/src/SFML/Window/Win32/ContextWGL.cpp @@ -261,20 +261,30 @@ void ContextWGL::CreateContext(ContextWGL* shared, unsigned int bitsPerPixel, co // Get the context to share display lists with HGLRC sharedContext = shared ? shared->myContext : NULL; - // Create the OpenGL context -- first try an OpenGL 3.0 context if it is supported - PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = reinterpret_cast(wglGetProcAddress("wglCreateContextAttribsARB")); - if (wglCreateContextAttribsARB) + // Create the OpenGL context -- first try an OpenGL 3.0 context if it is requested + if (settings.MajorVersion >= 3) { - int attributes[] = + PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = reinterpret_cast(wglGetProcAddress("wglCreateContextAttribsARB")); + if (wglCreateContextAttribsARB) { - WGL_CONTEXT_MAJOR_VERSION_ARB, 3, - WGL_CONTEXT_MINOR_VERSION_ARB, 0, - 0, 0 - }; - myContext = wglCreateContextAttribsARB(myDeviceContext, sharedContext, attributes); + int attributes[] = + { + WGL_CONTEXT_MAJOR_VERSION_ARB, settings.MajorVersion, + WGL_CONTEXT_MINOR_VERSION_ARB, settings.MinorVersion, + 0, 0 + }; + myContext = wglCreateContextAttribsARB(myDeviceContext, sharedContext, attributes); + } + + // If we couldn't create an OpenGL 3 context, adjust the settings + if (!myContext) + { + mySettings.MajorVersion = 2; + mySettings.MinorVersion = 0; + } } - // If the OpenGL 3.0 context failed, create a regular OpenGL 1.x context + // If the OpenGL 3.0 context failed or if we don't want one, create a regular OpenGL 1.x/2.x context if (!myContext) { myContext = wglCreateContext(myDeviceContext);