diff --git a/src/SFML/Graphics/GLExtensions.hpp b/src/SFML/Graphics/GLExtensions.hpp index 062a572d..de12af64 100644 --- a/src/SFML/Graphics/GLExtensions.hpp +++ b/src/SFML/Graphics/GLExtensions.hpp @@ -48,6 +48,7 @@ #define glFramebufferTexture2D glFramebufferTexture2DOES #define glCheckFramebufferStatus glCheckFramebufferStatusOES #define GL_FRAMEBUFFER GL_FRAMEBUFFER_OES + #define GL_FRAMEBUFFER_BINDING GL_FRAMEBUFFER_BINDING_OES #define GL_RENDERBUFFER GL_RENDERBUFFER_OES #define GL_COLOR_ATTACHMENT0 GL_COLOR_ATTACHMENT0_OES #define GL_DEPTH_ATTACHMENT GL_DEPTH_ATTACHMENT_OES @@ -75,6 +76,7 @@ #define glFramebufferTexture2D glFramebufferTexture2DEXT #define glCheckFramebufferStatus glCheckFramebufferStatusEXT #define GL_FRAMEBUFFER GL_FRAMEBUFFER_EXT + #define GL_FRAMEBUFFER_BINDING GL_FRAMEBUFFER_BINDING_EXT #define GL_RENDERBUFFER GL_RENDERBUFFER_EXT #define GL_COLOR_ATTACHMENT0 GL_COLOR_ATTACHMENT0_EXT #define GL_DEPTH_ATTACHMENT GL_DEPTH_ATTACHMENT_EXT diff --git a/src/SFML/Graphics/Texture.cpp b/src/SFML/Graphics/Texture.cpp index 96cbd3a6..7a5e1a9b 100644 --- a/src/SFML/Graphics/Texture.cpp +++ b/src/SFML/Graphics/Texture.cpp @@ -267,17 +267,22 @@ Image Texture::copyToImage() const std::vector pixels(m_size.x * m_size.y * 4); #ifdef SFML_OPENGL_ES - + // OpenGL ES doesn't have the glGetTexImage function, the only way to read // from a texture is to bind it to a FBO and use glReadPixels GLuint frameBuffer = 0; glCheck(glGenFramebuffers(1, &frameBuffer)); if (frameBuffer) { + GLint previousFrameBuffer; + glCheck(glGetIntegerv(GL_FRAMEBUFFER_BINDING, &previousFrameBuffer)); + glCheck(glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer)); glCheck(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_texture, 0)); glCheck(glReadPixels(0, 0, m_size.x, m_size.y, GL_RGBA, GL_UNSIGNED_BYTE, &pixels[0])); glCheck(glDeleteFramebuffers(1, &frameBuffer)); + + glCheck(glBindFramebuffer(GL_FRAMEBUFFER, previousFrameBuffer)); } #else