SFML community forums

Help => Graphics => Topic started by: YesBox on February 16, 2023, 12:44:13 am

Title: Do OpenGL calls work the same way on a sf::RenderTexture ?
Post by: YesBox on February 16, 2023, 12:44:13 am
I'm drawing everything to a sf::RenderTexture specifically so a shader has access to what's drawn on screen for further blending. Then I loop again to draw everything to the window (post shader stuff).

My game uses depth sorting. I've tried with and without the pushGLStates()/popGLStates(). Without them, nothing is drawn (to the render texture) that requires depth sorting. With them, everything appears but is not sorted properly.

For sf::RenderWindow, call push/popGlStates() are not necessary. The pure gl() functions work as is.

Does the sf::RenderTexture texture size need to match the world size (as opposed to the window size)? Are there any key differences between sf::RenderWindow and sf::RenderTexture?

for( VertexLevel vertex : *drawPtr ) { 
   if( cameraState_ == CameraState::ISOMETRIC_60D ) {
       
            glEnable(GL_DEPTH_TEST);   
            glEnable( GL_ALPHA_TEST );
            app->pixelBuffer_.pushGLStates();                   // sf::RenderTexture                                                                                           
            app->pixelBuffer_.draw( app->vtexMap_.at( vertex ), app->renderMap_.at( vertex ) );
            app->pixelBuffer_.popGLStates();

            glDisable( GL_DEPTH_TEST );
            glDisable( GL_ALPHA_TEST );
        }
}

        app->pixelBuffer_.display();
        app->testShader_.setUniform( "bufferTexture", app->pixelBuffer_.getTexture() );
 
Title: Re: Do OpenGL calls work the same way on a sf::RenderTexture ?
Post by: YesBox on February 16, 2023, 01:58:08 am
after playing around with it some more, the sf::RenderTexture does behave a bit differently.

You must enable depth sorting once at the start, and disable it once at the end, and calling push/popGLStates respectively.

Unlike window, which you can enable/disable it as much as you want.
Title: Re: Do OpenGL calls work the same way on a sf::RenderTexture ?
Post by: eXpl0it3r on February 16, 2023, 04:39:12 pm
push- and popGLStates only ensures that the GL states that SFML uses are set or reset. If you use any additional states, you'll have to manage those on your own.

Just because something "works" doesn't always mean that it's correct or will work on all the different platforms and PC component configurations. As such, it's better to follow the recommended guidelines.
Title: Re: Do OpenGL calls work the same way on a sf::RenderTexture ?
Post by: YesBox on February 25, 2023, 02:34:17 am
Where are the recommended guide lines?
Title: Re: Do OpenGL calls work the same way on a sf::RenderTexture ?
Post by: eXpl0it3r on February 26, 2023, 03:05:08 pm
https://www.sfml-dev.org/tutorials/2.5/window-opengl.php#using-opengl-together-with-the-graphics-module
Title: Re: Do OpenGL calls work the same way on a sf::RenderTexture ?
Post by: YesBox on February 26, 2023, 04:58:03 pm
Thanks!!!