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

Author Topic: A little help with sf::Vertex texturing  (Read 2380 times)

0 Members and 1 Guest are viewing this topic.

Jove

  • Full Member
  • ***
  • Posts: 114
    • View Profile
    • http://www.jestofevekites.com/
A little help with sf::Vertex texturing
« 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.
{much better code}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: A little help with sf::Vertex texturing
« Reply #1 on: April 28, 2012, 03:53:19 pm »
When you draw:
window.draw(vertices, 4, sf::Quads, &texture);
Laurent Gomila - SFML developer

Jove

  • Full Member
  • ***
  • Posts: 114
    • View Profile
    • http://www.jestofevekites.com/
Re: A little help with sf::Vertex texturing
« Reply #2 on: April 28, 2012, 03:58:28 pm »
Bingo! Thanks.  :)
{much better code}