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

Author Topic: setParameter not working?  (Read 3942 times)

0 Members and 1 Guest are viewing this topic.

Cuban-Pete

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
setParameter not working?
« 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
setParameter not working?
« Reply #1 on: July 03, 2011, 04:42:03 pm »
Hmm... could you provide a complete and minimal example that reproduces the problem?
Laurent Gomila - SFML developer

Cuban-Pete

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
setParameter not working?
« Reply #2 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:


//the shader is the one above in shader.txt - but I guess you figured that out already

Cuban-Pete

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
setParameter not working?
« Reply #3 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?  :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
setParameter not working?
« Reply #4 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.
Laurent Gomila - SFML developer

Cuban-Pete

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
setParameter not working?
« Reply #5 on: July 07, 2011, 07:55:24 pm »
Where is that error output?  :roll:

I shall try uniforms, thanks.  :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
setParameter not working?
« Reply #6 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.
Laurent Gomila - SFML developer

Cuban-Pete

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
setParameter not working?
« Reply #7 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();

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
setParameter not working?
« Reply #8 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());
Laurent Gomila - SFML developer

Cuban-Pete

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
setParameter not working?
« Reply #9 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).

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
setParameter not working?
« Reply #10 on: July 08, 2011, 09:46:56 pm »
Do this before writing to sf::Err(), and keep the ofstream instance alive.
Laurent Gomila - SFML developer

Cuban-Pete

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
setParameter not working?
« Reply #11 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
setParameter not working?
« Reply #12 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).
Laurent Gomila - SFML developer

 

anything