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

Author Topic: is it possible to draw indexed triangles?  (Read 2176 times)

0 Members and 1 Guest are viewing this topic.

NateS

  • Newbie
  • *
  • Posts: 16
    • View Profile
    • Email
is it possible to draw indexed triangles?
« on: April 28, 2014, 11:48:26 pm »
I'm writing the Spine runtime for SFML and I want to render a mesh. I have an array of vertices and UVs and I have an array of vertex indices that describe the triangles I want to draw (eg 0,1,2 ,1,2,3 ,2,3,4 would draw 3 triangles). Is it possible to draw this way using SFML? For now I'm just specifying the vertices multiple times, but this isn't ideal.
« Last Edit: April 29, 2014, 12:12:02 am by NateS »

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: is it possible to draw indexed triangles?
« Reply #1 on: April 29, 2014, 12:55:50 am »
SFML doesn't support indexed drawing. Add the vertices to an sf::VertexArray using the index to select the right vertex from the vertex array.
sf::VertexArray vertexArray(sf::Triangles, count);

for (int i = 0; i < count; i++)
{
    vertexArray[i] = vertices[indices[i]];
}
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

NateS

  • Newbie
  • *
  • Posts: 16
    • View Profile
    • Email
Re: is it possible to draw indexed triangles?
« Reply #2 on: April 29, 2014, 01:28:00 am »
Cool, that's what I'm doing, just wanted to check that I'm not missing something. Thanks!  8)

https://github.com/EsotericSoftware/spine-runtimes/blob/master/spine-sfml/src/spine/spine-sfml.cpp#L171

jannugimes

  • Guest
Re: is it possible to draw indexed triangles?
« Reply #3 on: May 19, 2014, 09:05:52 am »
SFML doesn't support indexed drawing. Add the vertices to an sf::VertexArray using the index to select the right vertex from the vertex array.
sf::VertexArray vertexArray(sf::Triangles, count);

for (int i = 0; i < count; i++)
{
    vertexArray[i] = vertices[indices[i]];
}
Very cool. That's what I was searching and now I have solved my problem.

 

anything