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

Author Topic: Nothing displaying with Modern OpenGL with SFML 2.5.0  (Read 2917 times)

0 Members and 1 Guest are viewing this topic.

gamepopper

  • Newbie
  • *
  • Posts: 35
    • View Profile
    • Email
Nothing displaying with Modern OpenGL with SFML 2.5.0
« on: May 20, 2018, 09:37:40 pm »
So I've been working on getting Vigilante Framework to support SFML 2.5.0, and I've been getting a few issues with the sf::RenderTexture. The main ones I've been going back and forth with eXpl0it3r on Twitter so I want to make this one separate and look for some help.

Basically, I use modern OpenGL rendering that's based on the Mastering SFML Game Development: Chapter 7 book by Raimondas. The key difference being that instead of rendering to an sf::RenderWindow I render to an sf::RenderTexture.

This implementation worked fine in 2.4.2 (as seen in the first attachment) but stops working 2.5.0. There is no error found using glGetError() and the only GL specific error I get is RenderTextureImplFBO (third attachment).

My only hint so far is that if I try to clear the RenderTexture to a specific colour, the screen doesn't display that colour, meaning that there could be a context issue causing the texture data not to display properly?

Also I'm not sure how about to create a simplified version of this project, since I need glew for the extensions and GLM for matrices since you cannot use the GL legacy stuff. I managed to convert the OpenGL example project to use modern OpenGL although texture coordinates and recreating the window to toggle sRGB aren't working properly.

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Nothing displaying with Modern OpenGL with SFML 2.5.0
« Reply #1 on: May 20, 2018, 11:32:57 pm »
There are already RenderTexture fixes pending for inclusion into a 2.5.1 release:

https://github.com/SFML/SFML/pull/1438
https://github.com/SFML/SFML/pull/1440
https://github.com/SFML/SFML/pull/1442

See if they help.

Also, don't refrain from posting your code anyway. Something is always better than nothing. I would rather install the dependencies and investigate than spend weeks trying to guess what the problem could be.
« Last Edit: May 20, 2018, 11:50:57 pm by binary1248 »
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

gamepopper

  • Newbie
  • *
  • Posts: 35
    • View Profile
    • Email
Re: Nothing displaying with Modern OpenGL with SFML 2.5.0
« Reply #2 on: May 21, 2018, 01:20:00 am »
Okay, the good news is that I fixed it myself!

What I was doing wrong was after rendering the 3D scene onto a render texture, I called resetGLStates() from the main render target AFTER rendering a sprite with the render texture set to it when I was supposed to call it.

const sf::Texture& V3DScene::GetTexture()
{
        sf::Texture::getMaximumSize();

        renderTex.setActive(true);
        renderTex.clear(BackgroundTint);
        glCheck(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
        glCheck(glViewport(0, 0, renderTex.getSize().x, renderTex.getSize().y));

        glCheck(glEnable(GL_DEPTH_TEST));
        glCheck(glEnable(GL_CULL_FACE));
        glCheck(glCullFace(GL_BACK));

        Shader->Bind();
        Shader->Update();

        for (unsigned int i = 0; i < members.size(); i++)
        {
                V3DObject* base = dynamic_cast<V3DObject*>(members[i]);

                if (base != nullptr && base->exists && base->visible)
                {
                        base->UpdateShader(Shader.get(), Camera.get());
                        base->Draw(renderTex);
                }
        }

        renderTex.display();
        renderTex.setActive(false);

        return renderTex.getTexture();
}

void V3DScene::Draw(sf::RenderTarget& RenderTarget)
{
        if (!visible)
                return;

        sf::Texture texture = GetTexture();

        if (PostEffect != nullptr && VPostEffectBase::isSupported())
        {
                postProcessTex.clear(sf::Color::Transparent);
                PostEffect->Apply(renderTex, postProcessTex);
                postProcessTex.display();

                updateTexture(postProcessTex.getTexture());
        }
        else
        {
                updateTexture(texture);
        }

        RenderTarget.resetGLStates();
        Sprite->Draw(RenderTarget);
}

One other positive out of this is that I got the OpenGL example fully working with modern OpenGL with GLM and GLEW, so if anyone wants a reference to how to use the OpenGL programmable pipeline in one cpp file, here you go!