SFML community forums

Help => Graphics => Topic started by: MarkJohnson94 on August 07, 2014, 06:09:21 pm

Title: Drawing a histogram plot
Post by: MarkJohnson94 on August 07, 2014, 06:09:21 pm
Hi there,

I have been working on an audio analysis library and I am currently working on a histogram of the loudness of the audio samples for the track. I have already developed a waveform viewer that has a few hundred points which are all connected by lines and this looks very nice. However for the histogram, I would like to have hundreds of individual lines which I can set the height of to display my histogram.

Is there any nice way to do this without having to create hundreds of individual objects? I'm a bit stuck for ideas.

Thanks for any help,
Mark
Title: Re: Drawing a histogram plot
Post by: Jesper Juhl on August 07, 2014, 06:12:18 pm
Creating a few hundred objects - one for each column in the histogram seems like the simplest and easiest solution to me. Nothing more than a basic loop and a few calculations. What don't you like about that approach?
Title: Re: Drawing a histogram plot
Post by: Hapax on August 07, 2014, 06:39:17 pm
I would suggest using a VertexArray, probably the same way your waveform viewer did (mine did).
Remember to use Lines (not LinesStrip) as the primitive type so that each pair of vertices define the line.
Title: Re: Drawing a histogram plot
Post by: MarkJohnson94 on August 11, 2014, 03:00:26 pm
Perfect. Jesper I understand your approach is probably better and thanks for the reply, I just wanted to know if there was a simple line or two of code that I could use to achieve the effect I needed, and using Lines not LinesStrip works great, so thanks Hapax.