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

Author Topic: [SOLVED] sf::VertexArray color after setting texture coords  (Read 2470 times)

0 Members and 1 Guest are viewing this topic.

zeno15

  • Newbie
  • *
  • Posts: 9
    • View Profile
    • Email
[SOLVED] sf::VertexArray color after setting texture coords
« on: August 05, 2013, 06:45:57 am »
I have a simple tile map that uses vertex arrays to display it, and it refers to a texture ive passed to it, it all works fine, I'm just curious as to what effect setting the color of the vertex's has?  I know when I set it to Transparent it shows the color used to clear the screen and when set to black it shows all black, but I was wondering if there was a more official answer than my trial and error,
Cheers
« Last Edit: August 05, 2013, 10:12:40 am by zeno15 »

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: sf::VertexArray color after setting texture coords
« Reply #1 on: August 05, 2013, 07:33:29 am »
A pixel color is the result of the interpolation of the color of its related vertices. ( http://www.sfml-dev.org/tutorials/2.1/images/graphics-vertex-array-triangle.png )
Then its color is multiplied with its texture color.

It can obviously be used to change the opacity, but you can also use it to colorize your texture. For example with the same greyscale grass texture, you could display it with several different shades of green (or whatever) just by modyfing its vertices colors.
(also works with sprite, if you use Sprite::setColor, it sets its 4 vertices to the given color)
« Last Edit: August 05, 2013, 07:36:13 am by G. »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::VertexArray color after setting texture coords
« Reply #2 on: August 05, 2013, 07:52:56 am »
The texture's pixels are modulated (multiplied) by the vertex color.
Laurent Gomila - SFML developer

zeno15

  • Newbie
  • *
  • Posts: 9
    • View Profile
    • Email
Re: sf::VertexArray color after setting texture coords
« Reply #3 on: August 05, 2013, 10:11:34 am »
Oh righto, that's excellent thanks :)

 

anything