diff options
Diffstat (limited to 'src/SFML/Graphics/RenderWindow.cpp')
-rw-r--r-- | src/SFML/Graphics/RenderWindow.cpp | 29 |
1 files changed, 9 insertions, 20 deletions
diff --git a/src/SFML/Graphics/RenderWindow.cpp b/src/SFML/Graphics/RenderWindow.cpp index d9e884d..eb56668 100644 --- a/src/SFML/Graphics/RenderWindow.cpp +++ b/src/SFML/Graphics/RenderWindow.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2016 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -26,7 +26,7 @@ // Headers //////////////////////////////////////////////////////////// #include <SFML/Graphics/RenderWindow.hpp> -#include <SFML/Graphics/GLCheck.hpp> +#include <SFML/Graphics/Texture.hpp> namespace sf @@ -78,24 +78,13 @@ Vector2u RenderWindow::getSize() const //////////////////////////////////////////////////////////// Image RenderWindow::capture() const { - Image image; - if (setActive()) - { - int width = static_cast<int>(getSize().x); - int height = static_cast<int>(getSize().y); - - // copy rows one by one and flip them (OpenGL's origin is bottom while SFML's origin is top) - std::vector<Uint8> pixels(width * height * 4); - for (int i = 0; i < height; ++i) - { - Uint8* ptr = &pixels[i * width * 4]; - glCheck(glReadPixels(0, height - i - 1, width, 1, GL_RGBA, GL_UNSIGNED_BYTE, ptr)); - } - - image.create(width, height, &pixels[0]); - } - - return image; + Vector2u windowSize = getSize(); + + Texture texture; + texture.create(windowSize.x, windowSize.y); + texture.update(*this); + + return texture.copyToImage(); } |