From f624f16350341f568fe61cbb3d6379e29becd459 Mon Sep 17 00:00:00 2001 From: laurentgom Date: Mon, 1 Jun 2009 13:41:38 +0000 Subject: [PATCH] Fixed windows' context not activated by default after their creation git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1119 4e206d99-4929-0410-ac5d-dfc041789085 --- samples/opengl/OpenGL.cpp | 8 +++---- src/SFML/Window/ContextGL.cpp | 2 +- src/SFML/Window/Window.cpp | 42 ++++++++++++++++++++++------------- 3 files changed, 31 insertions(+), 21 deletions(-) diff --git a/samples/opengl/OpenGL.cpp b/samples/opengl/OpenGL.cpp index 8fe54d75..e11c2c1e 100644 --- a/samples/opengl/OpenGL.cpp +++ b/samples/opengl/OpenGL.cpp @@ -15,16 +15,16 @@ //////////////////////////////////////////////////////////// int main() { + // Create main window + sf::RenderWindow App(sf::VideoMode(800, 600), "SFML OpenGL"); + App.PreserveOpenGLStates(true); + // Create a sprite for the background sf::Image BackgroundImage; if (!BackgroundImage.LoadFromFile("datas/opengl/background.jpg")) return EXIT_FAILURE; sf::Sprite Background(BackgroundImage); - // Create main window - sf::RenderWindow App(sf::VideoMode(800, 600), "SFML OpenGL"); - App.PreserveOpenGLStates(true); - // Load an OpenGL texture. // We could directly use a sf::Image as an OpenGL texture (with its Bind() member function), // but here we want more control on it (generate mipmaps, ...) so we create a new one from the image pixels diff --git a/src/SFML/Window/ContextGL.cpp b/src/SFML/Window/ContextGL.cpp index b49ef02b..93054f14 100644 --- a/src/SFML/Window/ContextGL.cpp +++ b/src/SFML/Window/ContextGL.cpp @@ -55,7 +55,7 @@ //////////////////////////////////////////////////////////// namespace { - // This thread-local variable will hold the "gloabl" context for each thread + // This thread-local variable will hold the "global" context for each thread sf::ThreadLocalPtr ThreadContext(NULL); // Now we create two global contexts. diff --git a/src/SFML/Window/Window.cpp b/src/SFML/Window/Window.cpp index 1320065e..6d59a5e0 100644 --- a/src/SFML/Window/Window.cpp +++ b/src/SFML/Window/Window.cpp @@ -140,16 +140,21 @@ void Window::Create(VideoMode Mode, const std::string& Title, unsigned long Wind delete myWindow; myWindow = priv::WindowImpl::New(Mode, Title, WindowStyle); - // Make sure another context is bound, so that: - // - the context creation can request OpenGL extensions if necessary - // - myContext can safely be destroyed (it's no longer bound) - Context Ctx; + { + // Make sure another context is bound, so that: + // - the context creation can request OpenGL extensions if necessary + // - myContext can safely be destroyed (it's no longer bound) + Context Ctx; - // Recreate the context - delete myContext; - myContext = priv::ContextGL::New(myWindow, Mode.BitsPerPixel, Settings); + // Recreate the context + delete myContext; + myContext = priv::ContextGL::New(myWindow, Mode.BitsPerPixel, Settings); - Initialize(); + Initialize(); + } + + // Activate the window's context + SetActive(); } @@ -162,16 +167,21 @@ void Window::Create(WindowHandle Handle, const ContextSettings& Settings) Close(); myWindow = priv::WindowImpl::New(Handle); - // Make sure another context is bound, so that: - // - the context creation can request OpenGL extensions if necessary - // - myContext can safely be destroyed (it's no longer bound) - Context Ctx; + { + // Make sure another context is bound, so that: + // - the context creation can request OpenGL extensions if necessary + // - myContext can safely be destroyed (it's no longer bound) + Context Ctx; - // Recreate the context - delete myContext; - myContext = priv::ContextGL::New(myWindow, VideoMode::GetDesktopMode().BitsPerPixel, Settings); + // Recreate the context + delete myContext; + myContext = priv::ContextGL::New(myWindow, VideoMode::GetDesktopMode().BitsPerPixel, Settings); - Initialize(); + Initialize(); + } + + // Activate the window's context + SetActive(); }