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

Author Topic: Drawing Vertex Arrays  (Read 1258 times)

0 Members and 1 Guest are viewing this topic.

Kev-In

  • Newbie
  • *
  • Posts: 3
    • View Profile
Drawing Vertex Arrays
« on: January 08, 2014, 09:03:29 pm »
It is possible to draw a quickly multidimensional vertex array?

For example     sf::Vertex vertex[800][600];

I know only this way, but isn't too fast...


for(i=0; i<800; i++)
{
     window.draw(vertex[i], 600, sf::Points);
}


Its like call .draw 800 times...

Thanks  :)


(and sorry for bad english)

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Drawing Vertex Arrays
« Reply #1 on: January 08, 2014, 09:37:10 pm »
Is there a reason why you don't keep a one-dimensional vertex array?

By the way, so many elements should rather be allocated on the freestore. That is, use sf::VertexArray instead of raw arrays (then you don't waste memory for vertices you don't use, either).
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Kev-In

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Drawing Vertex Arrays
« Reply #2 on: January 08, 2014, 10:45:59 pm »
Is there a reason why you don't keep a one-dimensional vertex array?

Yes, there is.


I need to assign to every vertex a x and y that corresponds to his array position.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Drawing Vertex Arrays
« Reply #3 on: January 08, 2014, 10:48:25 pm »
This is very well possible with a 1D array. Simply remap the indices:
std::size_t index = width * y + x;
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Kev-In

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Drawing Vertex Arrays
« Reply #4 on: January 08, 2014, 11:13:09 pm »
Thank you very much! :D

 Now it's much faster to draw :)