Hi, in a early post, I was wondering why some opengl functions didn't work with when I use a render texture, and I've found why, the raison is because the window have a n opengl 3 context and the rendertexture an opengl2 context, so, I've changed the render texture class to have the same context than the render window, by passing an sf::CotextSettings object instead of the boolean :
bool RenderTextureImplFBO::create(unsigned int width, unsigned int height, ContextSettings settings, unsigned int textureId)
{
// Create the context
m_context = new Context(settings, width, height);
// Create the framebuffer object
GLuint frameBuffer = 0;
glCheck(glGenFramebuffersEXT(1, &frameBuffer));
m_frameBuffer = static_cast<unsigned int>(frameBuffer);
if (!m_frameBuffer)
{
err() << "Impossible to create render texture (failed to create the frame buffer object)" << std::endl;
return false;
}
glCheck(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_frameBuffer));
// Create the depth buffer if requested
if (settings.depthBits > 0)
{
GLuint depth = 0;
glCheck(glGenRenderbuffersEXT(1, &depth));
m_depthBuffer = static_cast<unsigned int>(depth);
if (!m_depthBuffer)
{
err() << "Impossible to create render texture (failed to create the attached depth buffer)" << std::endl;
return false;
}
glCheck(glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_depthBuffer));
glCheck(glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, width, height));
glCheck(glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_depthBuffer));
}
// Link the texture to the frame buffer
glCheck(glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, textureId, 0));
// A final check, just to be sure...
if (glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) != GL_FRAMEBUFFER_COMPLETE_EXT)
{
glCheck(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0));
err() << "Impossible to create render texture (failed to link the target texture to the frame buffer)" << std::endl;
return false;
}
return true;
}
And now it works, when I want to load a shader after I create a rendertexture it doesn't tell me that only the GLSL 1.x is supported.
shadowMap = new RenderTexture();
lightMap = new RenderTexture();
normalMap = new RenderTexture();
shadowMap->create(frcm->getWindow().getSize().x, frcm->getWindow().getSize().y,frcm->getWindow().getSettings());
lightMap->create(frcm->getWindow().getSize().x, frcm->getWindow().getSize().y,frcm->getWindow().getSettings());
normalMap->create(frcm->getWindow().getSize().x, frcm->getWindow().getSize().y,frcm->getWindow().getSettings());
resolution = sf::Vector3i ((int) frcm->getWindow().getSize().x, (int) frcm->getWindow().getSize().y, frcm->getWindow().getView().getSize().z);
perPixLightingShader = new Shader();
buildNormalMapShader = new Shader();
glGetString get me the same version now before and after I create the render texture.
You should modify your render texture classes.