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

Author Topic: How to display texture on things drawn by sf::VertexArray  (Read 2029 times)

0 Members and 1 Guest are viewing this topic.

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
How to display texture on things drawn by sf::VertexArray
« on: August 05, 2012, 05:36:42 pm »
I understand all primitive types and how they treat every point but I don't think I understand how to texture anything.
Am I supposed to 'just' pass sf::RenderStates object with pointer to my texture in draw call like that?
        sf::RenderWindow app(sf::VideoMode(500,500),"test");
        sf::VertexArray ver(sf::Quads,4);
        sf::Texture test;
        test.loadFromFile("Old_Resources/est.tga");
        ver[0]=sf::Vertex(sf::Vector2f(0.f,0.f),sf::Vector2f(0.f,0.f));
        ver[1]=sf::Vertex(sf::Vector2f(128.f,0.f),sf::Vector2f(128.f,0.f));
        ver[2]=sf::Vertex(sf::Vector2f(128.f,128.f),sf::Vector2f(128.f,128.f));
        ver[3]=sf::Vertex(sf::Vector2f(0.f,128.f),sf::Vector2f(0.f,128.f));
        sf::RenderStates states;
        states.texture = &test;
while(1)
{
        app.clear();
        app.draw(ver,states);
        app.display();
}
 
Back to C++ gamedev with SFML in May 2023

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: How to display texture on things drawn by sf::VertexArray
« Reply #1 on: August 05, 2012, 06:33:15 pm »
Yes.

If you only define a single render state, you can even use a shortcut:
app.draw(ver,&test);
Laurent Gomila - SFML developer

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: How to display texture on things drawn by sf::VertexArray
« Reply #2 on: August 05, 2012, 06:39:08 pm »
Ok, thanks.
Back to C++ gamedev with SFML in May 2023