SFML community forums

Help => Graphics => Topic started by: Anonymous on July 02, 2014, 04:26:43 pm

Title: Drawing lines between points
Post by: Anonymous 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();
    }

}

(http://i.imgur.com/rhQraKk.png)
Title: Re: Drawing lines between points
Post by: Laurent on July 02, 2014, 04:28:12 pm
Change sf::Points to sf::LinesStrip.
Title: Re: Drawing lines between points
Post by: Anonymous on July 02, 2014, 04:32:22 pm
SFML is so nice to use, thanks!

(http://i.imgur.com/5pfVaye.png)
Title: Re: Drawing lines between points
Post by: Hapax on July 04, 2014, 01:57:07 am
I remember finding this for waveform display too. It really does make a difference!  :)