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 936 times)

0 Members and 1 Guest are viewing this topic.

FRex

  • Hero Member
  • *****
  • Posts: 1843
    • View Profile
    • My GitHub Page
    • 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();
}
 
ZipSavings, script to count rar/7z/zip savings: https://goo.gl/vvBj5M
LuaConsole: https://goo.gl/X4kRUk
FoxRaycaster: https://goo.gl/27nVS8
Small Games - Heart, Routing and Snek: https://goo.gl/15ZGWE https://goo.gl/k5gwWD https://goo.gl/4nKPnT
Botes - a notes app in Pascal: https://goo.gl/bzTqsi

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32466
    • 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: 1843
    • View Profile
    • My GitHub Page
    • Email
Re: How to display texture on things drawn by sf::VertexArray
« Reply #2 on: August 05, 2012, 06:39:08 pm »
Ok, thanks.
ZipSavings, script to count rar/7z/zip savings: https://goo.gl/vvBj5M
LuaConsole: https://goo.gl/X4kRUk
FoxRaycaster: https://goo.gl/27nVS8
Small Games - Heart, Routing and Snek: https://goo.gl/15ZGWE https://goo.gl/k5gwWD https://goo.gl/4nKPnT
Botes - a notes app in Pascal: https://goo.gl/bzTqsi

 

anything