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
This commit is contained in:
parent
d8dc34b199
commit
f624f16350
@ -15,16 +15,16 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
// Create main window
|
||||||
|
sf::RenderWindow App(sf::VideoMode(800, 600), "SFML OpenGL");
|
||||||
|
App.PreserveOpenGLStates(true);
|
||||||
|
|
||||||
// Create a sprite for the background
|
// Create a sprite for the background
|
||||||
sf::Image BackgroundImage;
|
sf::Image BackgroundImage;
|
||||||
if (!BackgroundImage.LoadFromFile("datas/opengl/background.jpg"))
|
if (!BackgroundImage.LoadFromFile("datas/opengl/background.jpg"))
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
sf::Sprite Background(BackgroundImage);
|
sf::Sprite Background(BackgroundImage);
|
||||||
|
|
||||||
// Create main window
|
|
||||||
sf::RenderWindow App(sf::VideoMode(800, 600), "SFML OpenGL");
|
|
||||||
App.PreserveOpenGLStates(true);
|
|
||||||
|
|
||||||
// Load an OpenGL texture.
|
// Load an OpenGL texture.
|
||||||
// We could directly use a sf::Image as an OpenGL texture (with its Bind() member function),
|
// 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
|
// but here we want more control on it (generate mipmaps, ...) so we create a new one from the image pixels
|
||||||
|
@ -55,7 +55,7 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
namespace
|
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<sf::priv::ContextGL> ThreadContext(NULL);
|
sf::ThreadLocalPtr<sf::priv::ContextGL> ThreadContext(NULL);
|
||||||
|
|
||||||
// Now we create two global contexts.
|
// Now we create two global contexts.
|
||||||
|
@ -140,6 +140,7 @@ void Window::Create(VideoMode Mode, const std::string& Title, unsigned long Wind
|
|||||||
delete myWindow;
|
delete myWindow;
|
||||||
myWindow = priv::WindowImpl::New(Mode, Title, WindowStyle);
|
myWindow = priv::WindowImpl::New(Mode, Title, WindowStyle);
|
||||||
|
|
||||||
|
{
|
||||||
// Make sure another context is bound, so that:
|
// Make sure another context is bound, so that:
|
||||||
// - the context creation can request OpenGL extensions if necessary
|
// - the context creation can request OpenGL extensions if necessary
|
||||||
// - myContext can safely be destroyed (it's no longer bound)
|
// - myContext can safely be destroyed (it's no longer bound)
|
||||||
@ -150,6 +151,10 @@ void Window::Create(VideoMode Mode, const std::string& Title, unsigned long Wind
|
|||||||
myContext = priv::ContextGL::New(myWindow, Mode.BitsPerPixel, Settings);
|
myContext = priv::ContextGL::New(myWindow, Mode.BitsPerPixel, Settings);
|
||||||
|
|
||||||
Initialize();
|
Initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Activate the window's context
|
||||||
|
SetActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -162,6 +167,7 @@ void Window::Create(WindowHandle Handle, const ContextSettings& Settings)
|
|||||||
Close();
|
Close();
|
||||||
myWindow = priv::WindowImpl::New(Handle);
|
myWindow = priv::WindowImpl::New(Handle);
|
||||||
|
|
||||||
|
{
|
||||||
// Make sure another context is bound, so that:
|
// Make sure another context is bound, so that:
|
||||||
// - the context creation can request OpenGL extensions if necessary
|
// - the context creation can request OpenGL extensions if necessary
|
||||||
// - myContext can safely be destroyed (it's no longer bound)
|
// - myContext can safely be destroyed (it's no longer bound)
|
||||||
@ -172,6 +178,10 @@ void Window::Create(WindowHandle Handle, const ContextSettings& Settings)
|
|||||||
myContext = priv::ContextGL::New(myWindow, VideoMode::GetDesktopMode().BitsPerPixel, Settings);
|
myContext = priv::ContextGL::New(myWindow, VideoMode::GetDesktopMode().BitsPerPixel, Settings);
|
||||||
|
|
||||||
Initialize();
|
Initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Activate the window's context
|
||||||
|
SetActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user