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

Author Topic: SFML and Shaders  (Read 387 times)

0 Members and 1 Guest are viewing this topic.

soupStand

  • Newbie
  • *
  • Posts: 1
    • View Profile
SFML and Shaders
« on: November 18, 2022, 06:59:09 pm »
I have a bit of a conundrum... using some old shaders I made long time ago with c++ and openGL, and trying to get them to work with SFML now...
I get this strange thing, when I use the background as the shader effect, but it only shows on 1/4 of the screen, but apparently it works.
Trying to troubleshoot why not full screen :D so... i'm wondering how to get the current window's boundaries..? something something getglobalbounds() ?
Thinking of sending the window boundaries to the shader and see if I can affect it... not even sure if this shrinking shader bug is in shaders itself or the c++ code :D

I am using this game example from a book, the game is called Thomas was Late and the book is Beginning C++ Game Programming that deals with SFML, C++ and just a little bit with GLSL.
There is a split screen option in the game but not sure how it would affect the shader to take only this quarter of a screen...?
Sorry, but it's really baffling me :D

Another thing, in general... How do you get the position sent to the shaders in SFML?
I haven't seen any good tutorial on it yet.
Like in "proper" openGL you usually use in vertex shader:

layout (location = 0) in vec3 aPos;

void main()
{
   gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);
}

but I'm not sure if this works in SFML like that?
All the examples I've seen use deprecated 1.0 stuff, that is really old.
I mean I try to use 3.3 core, and even that's old, but at least it's a bit modern...
« Last Edit: November 18, 2022, 07:02:07 pm by soupStand »

fallahn

  • Sr. Member
  • ****
  • Posts: 478
  • Buns.
    • View Profile
    • Trederia
Re: SFML and Shaders
« Reply #1 on: November 19, 2022, 02:52:57 pm »
Another thing, in general... How do you get the position sent to the shaders in SFML?
I haven't seen any good tutorial on it yet.
Like in "proper" openGL you usually use in vertex shader:

layout (location = 0) in vec3 aPos;

void main()
{
   gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);
}

but I'm not sure if this works in SFML like that?
All the examples I've seen use deprecated 1.0 stuff, that is really old.
I mean I try to use 3.3 core, and even that's old, but at least it's a bit modern...


If you're using the graphics module of SFML then up to version 2.5 (maybe 2.6, I've not kept up) you're restricted to GLSL 1.2 / #version 120 without a compatibility context. So, you're probably OK to use other versions of GLSL on Windows, maybe on Linux, and not at all on macOS which only supports core profiles.

The vertex position is provided in gl_Vertex and the world/view/projection matrix in gl_ModelViewProjectionMatrix - see the shader tutorial. It might also be worth noting that SFML drawables with 4 or fewer vertices will have their positions in world space with an identity matrix set for model/world matrix (this has caught me out before when trying to do lighting stuff, trying to take the inverse of it will just give you another identity matrix).