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

Author Topic: SFML only read and set uniform in GLSL Vertex Shader  (Read 1096 times)

0 Members and 1 Guest are viewing this topic.

Erid

  • Newbie
  • *
  • Posts: 3
    • View Profile
SFML only read and set uniform in GLSL Vertex Shader
« on: January 29, 2024, 02:16:07 am »
In my project, I was trying to use Both Vertex shader and Fragment shader, so in sf::Shader shader and i load 2 file, fragment and vertex like this
shader.loadFromFile("some_directory_to_fragment", sf::Shader::Fragment);
shader.loadFromFile("some_directory_to_vertex", sf::Shader::Vertex);
its was okay, but when i want set uniform like this:
shader.setUniform("radius", 30);
Its only find in vertex file and create error radius not found while the radius is in fragment shader, i could like delete the vertex line but i cannot do that since i need modify vertex, so How i fix this?, also i new to sfml, sorry if the help little bit `weird`

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: SFML only read and set uniform in GLSL Vertex Shader
« Reply #1 on: January 29, 2024, 03:10:29 am »
If you want a shader to have both a vertex shader and a fragment shader, you specify them together:
shader.loadFromFile("some_directory_to_vertex", "some_directory_to_fragment")

see here for more info:
https://www.sfml-dev.org/documentation/2.6.1/classsf_1_1Shader.php#ac9d7289966fcef562eeb92271c03e3dc

Note: the reason there's no semi-colon in my line of code is that this method should be used as a conditional. i.e. the return value of it should be tested
e.g.
if (!shader.loadFromFile("some_directory_to_vertex", "some_directory_to_fragment"))
    return EXIT_FAILURE;
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Erid

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: SFML only read and set uniform in GLSL Vertex Shader
« Reply #2 on: January 29, 2024, 04:48:29 am »
thank you, sorry if it bother because i new :P

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: SFML only read and set uniform in GLSL Vertex Shader
« Reply #3 on: January 29, 2024, 03:33:07 pm »
Not at all. You're welcome and hope it helps! :)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything