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

Author Topic: Drawing lines between points  (Read 3803 times)

0 Members and 1 Guest are viewing this topic.

Anonymous

  • Guest
Drawing lines between points
« on: July 02, 2014, 04:26:43 pm »
Hi,

I'm developing an audio application, and I am currently working on a waveform viewer.
My code currently draws 1x1 pixel points using the values stored in the multibuffer, and I would like to know how to draw lines between each of these points. This code from a tutorial on the website looked useful, but I wasn't sure how to dynamically set the points like I can do with my code below. Code from tutorial:
sf::Vertex vertices[2] =
{
    sf::Vertex(...),
    sf::Vertex(...)
};

window.draw(vertices, 2, sf::Lines);

I am aware my code is far from optimised at the moment. Any help would be great.

Thanks,
Mark

My current code:
window.setActive(true);
    while (window.isOpen())
    {
        clock.restart();
        sf::Event event;
        while (window.pollEvent(event))
        {
                        switch(event.type)
                        {
                        case sf::Event::Closed:
                                window.close();
                                break;
                        }
        }
               
                sf::VertexArray vertexPoints(sf::Points, windowX);
                for (int i = 0; i < 600; i++)
                {
                        vertexPoints[i].position = sf::Vector2f(i, (windowY/2)+multibuffer[0][i]*400);
                }
                window.setView(view);
        window.clear();
                window.draw(vertexPoints);
               
        window.display();
    }

}


Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Drawing lines between points
« Reply #1 on: July 02, 2014, 04:28:12 pm »
Change sf::Points to sf::LinesStrip.
Laurent Gomila - SFML developer

Anonymous

  • Guest
Re: Drawing lines between points
« Reply #2 on: July 02, 2014, 04:32:22 pm »
SFML is so nice to use, thanks!


Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Drawing lines between points
« Reply #3 on: July 04, 2014, 01:57:07 am »
I remember finding this for waveform display too. It really does make a difference!  :)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*