Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rendertexture produces upside down result #116

Closed
Groogy opened this issue Oct 30, 2011 · 7 comments
Closed

Rendertexture produces upside down result #116

Groogy opened this issue Oct 30, 2011 · 7 comments

Comments

@Groogy
Copy link

Groogy commented Oct 30, 2011

It is more like an unexpected behaviour more than a bug but still it blew me back a couple of hours in tracking down the source and it all came down to this.

If you render to a rendertexture and do not call Display before trying to use it, it might be possible for you to get a upside down result. It's not a major bug but it is confusing at the time if you just by accident missed to make the proper call. Having nothing being changed should be the proper behaviour if you ask me. It would also make it easier for the developer to guess what he did wrong.

Here's code for a simple example:

#include <SFML/Graphics.hpp>

int main(int argc, char** argv)
{
    sf::RenderWindow window;
    window.Create( sf::VideoMode( 800, 600 ), "RenderTexture mirror bug" );

    sf::RenderTexture texture;
    texture.Create( 800, 600 );

    sf::Text text;
    text.SetString( "Hello world!" );
    texture.Draw( text );
    //texture.Display();   // <- If this is run then the proper result is produced.

    sf::Sprite textureSprite( texture.GetTexture() );

    while( window.IsOpened() == true )
    {
        window.Clear();
        window.Draw( textureSprite );
        window.Display();

        sf::Event event;
        while( window.PollEvent( event ) == true )
        {
            if( event.Type == sf::Event::Closed )
            {
                window.Close();
                break;
            }
        }
    }
    return 0;
}

I've compiled and tested this on Windows, MinGW with Debug library and Nvidia card only.

@LaurentGomila
Copy link
Member

I can't change it. It happens for the most optimized RenderTexture implementation (FBO), which directly renders to the target texture.

@Groogy
Copy link
Author

Groogy commented Oct 30, 2011

It isn't possible to somehow to create a warning for it while running in Debug? Like if you are clearing the texture without having displayed it? So if we are doing a debug build we will get a warning printed out that we might be trying to use a unfinished texture? Or is that not a valid detection for it and is there no way to detect it?

Or you could do so that if Clear has been called then the texture returned in GetTexture will use an invalid OpenGL texture id and then nothing will be shown until Display is called(where you correct the OpenGL texture again) or something like that. But that might be overly complex to fix just something like this.

Not really important, just trying to come up with some solutions so that others won't fall into the same trap as I did. Like you pointed out it's something that happens inside the FBO and warning the user that he might be using the RenderTexture wrong is much work for little gain and maybe even will give false negative warnings.

@LaurentGomila
Copy link
Member

It isn't possible to somehow to create a warning for it while running in Debug? Like if you are clearing the texture without having displayed it? So if we are doing a debug build we will get a warning printed out that we might be trying to use a unfinished texture?

It would require to add ugly stuff to sf::Texture, I don't want to do that ;)

Or you could do so that if Clear has been called then the texture returned in GetTexture will use an invalid OpenGL texture id and then nothing will be shown until Display is called

It is valid to get a reference to the target texture at any time: before/during/after rendering. So GetTexture always returns a valid texture.

Not really important, just trying to come up with some solutions so that others won't fall into the same trap as I did.

If something goes wrong then read the doc. Isn't it enough? ;)

@Groogy
Copy link
Author

Groogy commented Oct 30, 2011

It would require to add ugly stuff to sf::Texture, I don't want to do that ;)

Suspected as much

If something goes wrong then read the doc. Isn't it enough? ;)

Well people are lazy and stupid, including me and they most probably won't read it until they've whined about it on the forum and then been told to read the documentation. Most generally, if something behaves unexpected then it is wrong. But like I said, this is more effort than gain really.

@nathanchere
Copy link

It caught me out as well, it's simple when you know what's happening but not very intuitive. Thanks for the explanation.

@Hibchibbler
Copy link

This one got me hard. But i see it was indeed my fault.

@ghost
Copy link

ghost commented Apr 19, 2018

Just got me. Would've taken me quite some time to realize I was missing a display, old post much appreciated :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants