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

Author Topic: SFML 2.1 FrameBufferObject alternative with postprocessing shader?  (Read 2248 times)

0 Members and 1 Guest are viewing this topic.

Holland

  • Newbie
  • *
  • Posts: 5
    • View Profile
SFML 2.1 FrameBufferObject alternative with postprocessing shader?
« on: September 11, 2014, 11:51:45 am »
Hey guys, does anyone have an example of a shader attached to the RenderTexture?

In the shader tutorial it says you can simply do

window.draw(sf::Sprite(m_FBO.getTexture()), m_ScreenShader);

But it's not in the API documentation, nor can I use it this way. I am new to SFML, so help would be awesome :)
« Last Edit: September 11, 2014, 12:12:07 pm by Holland »

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: SFML 2.1 FrameBufferObject alternative with postprocessing shader?
« Reply #1 on: September 11, 2014, 12:43:02 pm »
You have to create a sprite to draw the texture to the window.

sf::Sprite sprite(m_FBO.getTexture());
window.draw(sprite, shader);


AlexAUT

Holland

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: SFML 2.1 FrameBufferObject alternative with postprocessing shader?
« Reply #2 on: September 11, 2014, 01:15:08 pm »
Your edit gave me this error, which is the same for my code.
Quote
error C2664: 'void sf::RenderTarget::draw(const sf::Vertex *,unsigned int,sf::PrimitiveType,const sf::RenderStates &)' : cannot convert argument 2 from 'sf::Shader' to 'const sf::RenderStates &'
1>          Reason: cannot convert from 'sf::Shader' to 'const sf::RenderStates'

It's basically the example that I gave that doesn't work, there's little to no difference between
window.draw(sf::Sprite(m_FBO.getTexture()), m_ScreenShader);
and
sf::Sprite sprite(m_FBO.getTexture());
window.draw(sprite, m_ScreenShader);

Currently I am trying other stuff out, this seems to look like what I need, but need to test it out if it truly renders to m_FBO before m_FBO.display();. Haven't created any test objects.
void Application::Render()
{
        m_FBO.display();
        m_ScreenShader.setParameter("m_Texture", m_Texture);
        sf::Shader::bind(&m_ScreenShader);
        draw(sf::Sprite(m_FBO.getTexture()));

        display();     
        sf::Shader::bind(0);
}

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: SFML 2.1 FrameBufferObject alternative with postprocessing shader?
« Reply #3 on: September 11, 2014, 01:19:42 pm »
It's basically the example that I gave that doesn't work, there's little to no difference between

Sry i didn't saw the sf::Sprite(texture), I thought you wanted to draw the texture directly ::)


AlexAUT

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: SFML 2.1 FrameBufferObject alternative with postprocessing shader?
« Reply #4 on: September 11, 2014, 02:45:35 pm »
The 2nd parameter of draw is a RenderStates which can be built implicitly from a pointer to shader.

Try window.draw(sf::Sprite(m_FBO.getTexture()), &m_ScreenShader); instead.
SFML / OS X developer

Holland

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: SFML 2.1 FrameBufferObject alternative with postprocessing shader?
« Reply #5 on: September 11, 2014, 04:18:58 pm »
Ah, that did it! Now to figure out if it actually renders.. Getting a completely white screen.

Holland

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: SFML 2.1 FrameBufferObject alternative with postprocessing shader?
« Reply #6 on: September 15, 2014, 04:01:30 pm »
Hey guys, still here. Wondering if anyone could help me get this mother running.

I was literally typing this when I found out what I was doing wrong. Anyway, I was using Vertex Buffer Objects, some OpenGL functions and stuff, when I found out that window.draw() needs resetGLStates to work correctly after OpenGL calls. So that's what I added, and now it works!

                g_FBO.setActive(); // Have to do this or it complains about the VBOs
                IdleGL(); // Idle function of GL
                DisplayGL(); // Render function
                g_Window->resetGLStates(); // Reset GL states
                g_Window->draw(sf::Sprite(g_FBO.getTexture())); // Draw texture as sprite.
                g_Window->display(); // Display window

Also, I created the FBO with a depth texture of course!

 

anything