SFML community forums

Help => Graphics => Topic started by: Jove on April 28, 2012, 02:19:50 pm

Title: A little help with sf::Vertex texturing
Post by: Jove on April 28, 2012, 02:19:50 pm
I've taken a step towards working with Vertex Arrays today, but am slightly confused about texturing.

// define a 100x100 square, red, with a 10x10 texture mapped on it
 sf::Vertex vertices[] =
 {
     sf::Vertex(sf::Vector2f(  0,   0), sf::Color::Red, sf::Vector2f( 0,  0)),
     sf::Vertex(sf::Vector2f(  0, 100), sf::Color::Red, sf::Vector2f( 0, 10)),
     sf::Vertex(sf::Vector2f(100, 100), sf::Color::Red, sf::Vector2f(10, 10)),
     sf::Vertex(sf::Vector2f(100,   0), sf::Color::Red, sf::Vector2f(10,  0))
 };

 // draw it
 window.draw(vertices, 4, sf::Quads);

The example from the documentation is simple enough, but how do you tell it what/where the texture is that these coordinates (10x10) refer to?

Thanks.
Title: Re: A little help with sf::Vertex texturing
Post by: Laurent on April 28, 2012, 03:53:19 pm
When you draw:
window.draw(vertices, 4, sf::Quads, &texture);
Title: Re: A little help with sf::Vertex texturing
Post by: Jove on April 28, 2012, 03:58:28 pm
Bingo! Thanks.  :)