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

Author Topic: Do OpenGL calls work the same way on a sf::RenderTexture ?  (Read 1814 times)

0 Members and 2 Guests are viewing this topic.

YesBox

  • Newbie
  • *
  • Posts: 11
    • View Profile
Do OpenGL calls work the same way on a sf::RenderTexture ?
« 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() );
 

YesBox

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Do OpenGL calls work the same way on a sf::RenderTexture ?
« Reply #1 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.
« Last Edit: February 16, 2023, 03:18:10 pm by YesBox »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Do OpenGL calls work the same way on a sf::RenderTexture ?
« Reply #2 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

YesBox

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Do OpenGL calls work the same way on a sf::RenderTexture ?
« Reply #3 on: February 25, 2023, 02:34:17 am »
Where are the recommended guide lines?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

YesBox

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Do OpenGL calls work the same way on a sf::RenderTexture ?
« Reply #5 on: February 26, 2023, 04:58:03 pm »
Thanks!!!