SFML community forums

Help => Graphics => Topic started by: FRex on August 05, 2012, 05:36:42 pm

Title: How to display texture on things drawn by sf::VertexArray
Post by: FRex 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();
}
 
Title: Re: How to display texture on things drawn by sf::VertexArray
Post by: Laurent 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);
Title: Re: How to display texture on things drawn by sf::VertexArray
Post by: FRex on August 05, 2012, 06:39:08 pm
Ok, thanks.