SFML community forums

Help => Graphics => Topic started by: Cuban-Pete on July 03, 2011, 03:59:49 pm

Title: setParameter not working?
Post by: Cuban-Pete on July 03, 2011, 03:59:49 pm
I cannot get it to work. I have this very very complicated shader... :P

Code: [Select]

varying vec4 normalColor;

void main( void )
{  
   gl_FragColor = normalColor;
}


and I have this in my program:

Code: [Select]
sf::Shader shader;
if(!shader.LoadFromFile("shader.txt")){
return 0;}
if(shader.IsAvailable()) info = " shader available";
shader.SetParameter("normalColor", 1.f, 0.f, 0.f, .5f);


I also use:
Code: [Select]

shader.Bind(); //move into function?
// opengl stuff
shader.Unbind(); //move into function?


I know the shader is working because IsAvailable return true and my opengl content is completely black.
Title: setParameter not working?
Post by: Laurent on July 03, 2011, 04:42:03 pm
Hmm... could you provide a complete and minimal example that reproduces the problem?
Title: setParameter not working?
Post by: Cuban-Pete on July 03, 2011, 06:16:54 pm
I modified the window example to this: https://legacy.sfmluploads.org/index.php?page=view_code&id=42

It gets even crazier...  :shock: ... after compiling I get this message from my virus protector:
(https://legacy.sfmluploads.org/cache/pics/46_error.png)

//the shader is the one above in shader.txt - but I guess you figured that out already
Title: setParameter not working?
Post by: Cuban-Pete on July 07, 2011, 06:32:32 pm
The virus warning doesn't mather to me right now, but the parameter problem does. Did you try the example code and could you reproduce it?  :)
Title: setParameter not working?
Post by: Laurent on July 07, 2011, 07:38:03 pm
Hmm the standard output says everything that you need to know (SFML uses the error output intensively so it's a very bad idea to ignore it...) ;)

It says that the "normalColor" parameter doesn't exist, which is true since it's a varying but should be a uniform instead. Varying variables are meant to be written by a vertex shader and transmitted to the fragment shader, applying interpolation on the values. Parameters assigned by the code must be uniforms.
Title: setParameter not working?
Post by: Cuban-Pete on July 07, 2011, 07:55:24 pm
Where is that error output?  :roll:

I shall try uniforms, thanks.  :)
Title: setParameter not working?
Post by: Laurent on July 07, 2011, 08:45:06 pm
Quote
Where is that error output?

sf::Err(), which outputs to the same target as stderr by default (the console). You can either keep the console in your project, or redirect sf::Err() to a file.
Title: setParameter not working?
Post by: Cuban-Pete on July 08, 2011, 08:01:09 pm
Yes, the problem is solved. Changing to uniform made it work.  :oops:

I also tried to write sf::Err() to a txt file, but only got numbers. I think the flag is off?

I did it this way:

Code: [Select]

std::ofstream file;
file.open("debug.txt");
file << "Error: " << sf::Err();
file.close();
Title: setParameter not working?
Post by: Laurent on July 08, 2011, 09:10:08 pm
You're doing it wrong ;)

Code: [Select]
std::ofstream file("debug.txt");
sf::Err().rdbuf(file.rdbuf());
Title: setParameter not working?
Post by: Cuban-Pete on July 08, 2011, 09:43:15 pm
Quote from: "Laurent"
You're doing it wrong ;)

Code: [Select]
std::ofstream file("debug.txt");
sf::Err().rdbuf(file.rdbuf());


Does it matter when you call it? I'm getting no errors (after recreating the problem in this topic).
Title: setParameter not working?
Post by: Laurent on July 08, 2011, 09:46:56 pm
Do this before writing to sf::Err(), and keep the ofstream instance alive.
Title: setParameter not working?
Post by: Cuban-Pete on July 08, 2011, 10:15:41 pm
Writing to sf::Err()? Huh?  :( I thought sf::Err() is like a function that when you call it, it puts out all the encountered errors...

Keep instance alive? For how long?

I just use it like this at the end of the while loop:

Code: [Select]
if(someButtonBool){
std::ofstream file("debug.txt");
sf::Err().rdbuf(file.rdbuf());
file.close();
}


Sorry for wasting your time, but I don't get it. Is there perhaps a complete code example?
Title: setParameter not working?
Post by: Laurent on July 08, 2011, 11:09:06 pm
sf::Err() is a standard stream, just like std::cout or std::cerr. It's an object that SFML uses to write errors, it's not a function that outputs something.

So you must redirect it at the beginning, and keep the ofstream alive as long as sf::Err() uses its streambuf (what rdbuf() returns).