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

Author Topic: VertexArray repeat texture [Solved]  (Read 2042 times)

0 Members and 1 Guest are viewing this topic.

cheeseboy

  • Newbie
  • *
  • Posts: 36
    • View Profile
VertexArray repeat texture [Solved]
« on: December 25, 2014, 09:17:33 am »
How do I repeat a texture without stretching it across the size of the vertex array?

I've tried this: but it seems  to stretch the checkers.

Relevant Code: (rect is area I would like to repeat texture in. the texture is 64x64 px)
sf::Texture checkers;
checkers.loadFromImage(*createChecker());
checkers.setRepeated(true);

void Checkers::setTextureRect(sf::IntRect rect)
{
        // size //
        m_vertices[0].position = sf::Vector2f(0,0);
        m_vertices[1].position = sf::Vector2f(rect.width,0);
        m_vertices[2].position = sf::Vector2f(rect.width, rect.height);
        m_vertices[3].position = sf::Vector2f(0,rect.height);
       
        m_vertices[0].texCoords = sf::Vector2f(0,0);
        m_vertices[1].texCoords = sf::Vector2f(64,0);
        m_vertices[2].texCoords = sf::Vector2f(64, 64);
        m_vertices[3].texCoords = sf::Vector2f(0,64);
}

void Checkers::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
    states.transform *= getTransform();
    states.texture = checkers;

    target.draw(m_vertices, states);
}
« Last Edit: December 25, 2014, 01:14:12 pm by cheeseboy »

fallahn

  • Hero Member
  • *****
  • Posts: 507
  • Buns.
    • View Profile
    • Trederia
Re: VertexArray repeat texture
« Reply #1 on: December 25, 2014, 10:38:39 am »
Increase the texture coordinates while keeping the positions the same. For example setting the coords to 128 on a 64px wide texture will repeat it twice

cheeseboy

  • Newbie
  • *
  • Posts: 36
    • View Profile
Re: VertexArray repeat texture
« Reply #2 on: December 25, 2014, 01:13:54 pm »
Fixed. Thanks.

 

anything