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

Author Topic: Shader flips output  (Read 1666 times)

0 Members and 1 Guest are viewing this topic.

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Shader flips output
« on: January 06, 2013, 09:05:29 pm »
I only found one thread about that, which was made before 2.0, most others were related to rendertexture and display() on it.
Simply drawing a sprite with this shader, while I remove middle line, will flip the output.
uniform sampler2D my_texture;//sf::Shader::CurrentTexture
uniform vec2 my_tex_size;//it's size

void main()
{
        vec2 coords=gl_FragCoord.xy/my_tex_size;
        coords.y=1.0-coords.y;
        gl_FragColor=texture2D(my_texture,coords);
}
Is this expected to happen? I know SFML flips y for itself(right?). So does it mean I need to too to get same output?
Back to C++ gamedev with SFML in May 2023

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Shader flips output
« Reply #1 on: January 06, 2013, 10:45:20 pm »
Your texture coordinates should already be normalized in the fragment shader, ie. you should not have to divide them by the texture size.

But anyway, this does not explain your problem. Could you post a complete and minimal code that reproduces the problem?
Laurent Gomila - SFML developer

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Shader flips output
« Reply #2 on: January 06, 2013, 11:26:15 pm »
Ok, no problem after all. I was reading this:
http://www.sfml-dev.org/tutorials/1.6/graphics-postfx.php
and since you mistyped gl_TexCoord[0] as gl_TexCoords[0] it was not compiling so I thought it's not supported for my card and changed it to closest thing that does almost same: gl_FragCoord, which are not normalized and have y flipped compared to SFML:
http://www.opengl.org/sdk/docs/manglsl/xhtml/gl_FragCoord.xml
Back to C++ gamedev with SFML in May 2023

 

anything