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

Author Topic: Drawing lines is incredibly slow?  (Read 1733 times)

0 Members and 1 Guest are viewing this topic.


  • Full Member
  • ***
  • Posts: 157
    • View Profile
Drawing lines is incredibly slow?
« on: September 25, 2012, 02:54:08 am »
I'm currently trying to replicate this tutorial [http://gamedev.tutsplus.com/tutorials/implementation/simulate-fabric-and-ragdolls-with-simple-verlet-integration/] and I'm getting low FPS when I try to draw a grid. 

I have 2500 points on screen, each spaced 6 pixels apart from each other, and I want to draw a line between each point and its neighbor.  When I do so, my FPS goes from 4200 to 20-100.  Is this normal, or am I doing something wrong?

Here's the code I'm using to draw the lines.
void SFML_Program::drawLine(sf::Vector2f a, sf::Vector2f b)
        sf::Vertex line[2] = {a, b};
        MainWindow.draw(line, 2, sf::Lines);

I've also tried:
        void SFML_Program::drawLine(sf::Vector2f a, sf::Vector2f b)
        sf::VertexArray lines(sf::Lines, 2);
        lines[0].position = a;
        lines[1].position = b;

I'm calling that 4900 times to produce this. 


The code that calls it simply retrieves the two points it needs and then calls the drawline.  Am I doing something wrong?
« Last Edit: September 25, 2012, 08:15:30 am by Laurent »


  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Drawing lines is incredibly slow?
« Reply #1 on: September 25, 2012, 08:15:10 am »
Drawing 4900 lines this way requires 4900 OpenGL calls, to render 4900 tiny geometries. To get good performances, you'd rather draw one big vertex array containing the 4900 lines, in a single call.
Laurent Gomila - SFML developer