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

Author Topic: Documentation error on shaders.  (Read 3682 times)

0 Members and 1 Guest are viewing this topic.

Lupinius

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
Documentation error on shaders.
« on: March 31, 2012, 05:49:31 pm »
The documentation (of SFML2) claims that you can use window.draw(sprite, shader); to draw something using a shader, when in reality this function does not exist anymore (or I'm just too blind to find it).

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Documentation error on shaders.
« Reply #1 on: March 31, 2012, 06:57:55 pm »
It's Window::draw(Sprite, RenderStates) + the implicit constructor RenderStates::RenderStates(Shader*) which allows to write this.

You would have seen it by reading the documentation of the sf::RenderStates class.
Laurent Gomila - SFML developer

Lupinius

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
Re: Documentation error on shaders.
« Reply #2 on: March 31, 2012, 07:37:04 pm »
I did actually use this, the documentation for the shader explicitly states this though:
Quote
To apply a shader to a drawable, you must pass it as an additional parameter to the Draw function:

window.draw(sprite, shader);

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Documentation error on shaders.
« Reply #3 on: March 31, 2012, 08:15:07 pm »
Do you mean that this part of the doc is misleading? Because, right below, there is:
Quote
... which is in fact just a shortcut for this:
Code: [Select]
sf::RenderStates states;
states.shader = shader;
window.draw(sprite, states);
Laurent Gomila - SFML developer

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Re: Documentation error on shaders.
« Reply #4 on: March 31, 2012, 10:36:25 pm »
The problem is probably that he have shader defined as:
sf::Shader shader;
when the RenderStates class expects a pointer. For it to work for him he has to take the reference to the shader by adding the & operator.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Documentation error on shaders.
« Reply #5 on: March 31, 2012, 10:52:53 pm »
Quote
the reference to the shader by adding the & operator.
The address of, not the reference to ;)
Laurent Gomila - SFML developer

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Re: Documentation error on shaders.
« Reply #6 on: March 31, 2012, 10:59:20 pm »
Quote
the reference to the shader by adding the & operator.
The address of, not the reference to ;)

My mistake ^^
The operator name is "Reference" but is read as "Address of"
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Documentation error on shaders.
« Reply #7 on: March 31, 2012, 11:09:52 pm »
& just has multiple meanings in C++:
  • Type& is a reference to Type
  • &expr is the (unary) address-of operator
  • expr&expr is the (binary) bitwise AND operator
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Re: Documentation error on shaders.
« Reply #8 on: March 31, 2012, 11:13:57 pm »
  • &expr is the (unary) address-of operator
Are you sure? According to Wikipedia it's name is Reference.
http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B#Member_and_pointer_operators
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

Lupinius

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
Re: Documentation error on shaders.
« Reply #9 on: March 31, 2012, 11:25:22 pm »
Damn, I didn't get that the shader variable in the example line has to be a pointer. Guess I was confused because a variable with the same name was used as an object. Looking at the longer variant again it makes sense though. Thanks for the clearing that up :)

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Documentation error on shaders.
« Reply #10 on: April 01, 2012, 09:56:32 am »
Are you sure? According to Wikipedia it's name is Reference.
Yes, the standard mentions "address-of operator". Wikipedia is not a reliable source when it comes to C++ details. It's good to get an overview (also concerning C++11), but for in-depth knowledge there are better sources.

I guess they called it "reference" as an opposite to "dereference", but this is confusing because of the other meaning of &, namely the reference declarator (when used with a type). No one understands you when you say "reference" and mean "address-of" ;)
« Last Edit: April 01, 2012, 09:58:03 am by Nexus »
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything