Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Bug with render textures.  (Read 2314 times)

0 Members and 1 Guest are viewing this topic.

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Bug with render textures.
« on: July 13, 2014, 10:47:06 am »
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.

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Bug with render textures.
« Reply #1 on: July 13, 2014, 11:05:12 am »
Wait... is this a serious post? Because we have told you countless times that sfml-graphics only works with compatibility contexts. This means, since you obviously can't add it all up yourself:

sfml-graphics will not allow you to use GLSL 1.30 or higher on systems that are only able to provide GLSL 1.30 or higher exclusively in core contexts.

This is not a bug. Read what I just said over and over again if you still can't understand it. sfml-graphics requires a compatibility context, so fixing RenderTexture so that it works even on half-implemented systems is not something we will do. If you really need to use Framebuffer Objects on those systems, code it yourself. It isn't that hard. After all, there are many places you can copy and paste code from.

If you are lucky, this situation will improve as part of SFML 3, but really, don't post any more things like that, please.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Re: Bug with render textures.
« Reply #2 on: July 13, 2014, 11:50:41 am »
Ha, ok, ok.. sorry.

I don't know when SFML3'll be released so, I think I'll recode all by myself with a support of all opengl's version.

Here I need to do instanced rendering also...
« Last Edit: July 13, 2014, 11:52:35 am by Lolilolight »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Bug with render textures.
« Reply #3 on: July 13, 2014, 12:22:47 pm »
I don't know when SFML3'll be released so, I think I'll recode all by myself with a support of all opengl's version.
Good idea, re-implementing everything has proven very well in the past.

If you absolutely want to waste your time yet another time, then so be it, but please leave the SFML community out of this. That is, don't keep us up-to-date about the progress or alleged bug reports. Thanks.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything