Fill between lines?

Hello,
I am relatively new in the OpenGL scene, so I went straight for the beginner section…

I use OpenGL to code a scientific visualization piece of software… mostly 2D visu for now

I stumbled upon an issue when trying to implement a line fill type of plotting ability (something of this type: http://gnuplot.sourceforge.net/demo_4.3/fillbetween.1.png)

Of course I am thinking of writing an algorithm to map this space with triangles…but I am sure this is a classic task, some maybe there something ready-made for this?

I was wondering if a fragment shader would help…change the color of something based on where they lie in space? something like that…

On a similar topic, if I want to draw 1000 lines (filled) of 5000 points… I calculate roughly that I would need 7.5 millions triangles…

I see in the technical spec of my card (quadro fx1700) that it can render 191 millions triangles/sec, does that mean that
that I can render my scene 25 times / sec at max = rendering that scene would take 1/25 sec…?

Thanks for any answer! :slight_smile:

There are libs able to fill triangles from edges, I played with “triangle” lib which is simple for simple things, and can do more complex things :
http://www.cs.cmu.edu/~quake/triangle.html

However if “lie between” has the same number of points for low and high lines, it is very easy to build a triangle strip :
tri 0 : take 2 first high points, then 0th low
tri 1 : take 2 first low points, then 1st low
…etc…

About performance, the theorical performance is a maximum, under optimal conditions, so actual perf will be below that.

Does your data evolves over time, or do you only need to navigate around a fixed graph ?

Thanks for the link…it look it would do what I want…
I’ll see if I figure out how to use it…

For this case I agree, but my case is more like:
imagine a noisy line centered around a zero value, part of line above zero must be filled with white, part below with black…

So it’s not straightforward to do a strip (especially because of the color stuff)…(or is it?)
i did come up with a theoritical system to do that…but was checking for something maybe obvious…

Data would be updated every 2 to 10 seconds or upon user requests, nothing stressful… no need to have smooth animation here, thank god :smiley:

I just still hope that the rendering time would be significantly better than just the average plotting lib…

thx for your answer.

Should be easy, either with a black/white texture and appropriate texture coordinates (and GL_NEAREST interpolation), or with a fragment shader (may provide more performance on some cards). The shader route demands some setup but is very versatile and easy to customize once working.

25 fps redraw for a 1000*5000 points sound way better than average plotting lib :slight_smile:

Should be easy, either with a black/white texture and appropriate texture coordinates (and GL_NEAREST interpolation), or with a fragment shader (may provide more performance on some cards). The shader route demands some setup but is very versatile and easy to customize once working.
[/QUOTE]

Ok I’ll spend some time reading about shaders then, no need to ask stupid questions just yet…

25 fps redraw for a 1000*5000 points sound way better than average plotting lib :)[/QUOTE]

Ah ah! I knew I wasn’t wasting my time :smiley:

Thanks!

ZbuffeR (or whoever feels like it), do you mind detailling what you were thinking in the "shader " road?

I went through the Orange book, and I’m still unclear of how to start…

Is it exploiting the fact that glPosition output of the vertex shader is different that glFragCoord in the fragment shader, so you know somehow in a filled section, and so decided if the glFragColor is going to be Black or White?

The other options, (texture), I think I understand the concept…even though i cant make it work 'til now…

Thanks for any answers :smiley:

Store the plot values into vertices attributes, wich gets linearly interpolated between vertices. So in fragment shader you just have to do something like that :

if (myAttribute>0.0) {
// black
gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
} else {
// white
gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
}

Ok, before I was using a texture to pass the plot value…
Is it fundamentally different, because I had a piece of code somewhat similar to what you show here…

But it was, affecting only the line itself (I passed the vertices as GL_LINE_STRIP)… below 0, the line was black, above white…

So I am guessing the primitive mode in which you are passing your vertices matters…and then I am back to my original question…how to subdivide the spaces between two (many, in fact) lines (that may intersect and all…)

Or are you suggesting something else?

(sorry if I am annoyingly slow to understand this! :D)