Reputation: 77485
I'm experimenting with OpenGL (for performance reasons) for drawing scatterplots. I'm interested in both 2D and 3D.
What options do I have for styling markers, to make e.g. different groups visible?
Obviously I can vary the color. But in "traditional" scatterplots, one also uses circles, plusses, Xes, boxes etc. - how do I best achieve these in OpenGL scatterplots?
Should I render desired 2D markers to a small texture and then draw one triangles with the texture for each marker? Can I use a texture for alpha only, but use a dynamic color? (to e.g. have texture = class, color = other score)?
Are there any extra cool ways for styling markers in OpenGL that I don't have in regular plotting libraries (say, gnuplot)?
Any hints for performance? Display lists or vertex buffers?
Upvotes: 2
Views: 2483
Reputation: 182073
That's a lot of questions. Let me tackle them one by one.
What options do I have for styling markers, to make e.g. different groups visible?
Colour, shape, size, and even animation.
Obviously I can vary the color. But in "traditional" scatterplots, one also uses circles, plusses, Xes, boxes etc. - how do I best achieve these in OpenGL scatterplots?
Billboard sprites (tutorial). The idea is to draw a small quad, oriented so that it always faces the camera. This rotation can be done on the CPU, but if the camera moves and you need to recalculate it each frame, it's likely faster to do it in a vertex shader.
Should I render desired 2D markers to a small texture and then draw one triangles with the texture for each marker?
Two triangles (i.e. a square) is the usual approach, because squares are easier to texture.
Can I use a texture for alpha only, but use a dynamic color? (to e.g. have texture = class, color = other score)?
Yes. If you use the fixed pipeline, textures will be modulated by the current colour. In other words, if you have a white marker with alpha in your texture, and you set the current colour to red, you will get a red marker. If you're using shaders, you'll have to do this in your fragment shader.
Are there any extra cool ways for styling markers in OpenGL that I don't have in regular plotting libraries (say, gnuplot)?
Like I mentioned: animation. You could make your marker spin around, bob up and down, or wiggle around randomly at various speeds. I once heard of a computer network visualisation system where water would drip out of a computer icon to indicate packet loss, and smoke and fire would come out to indicate a hot CPU. The limit is your imagination!
Any hints for performance? Display lists or vertex buffers?
Vertex buffers. Possibly shaders. But depending on the size of your data set and your experience with OpenGL, you could get away without either.
Try the simplest thing first, and if it's too slow, replace the bottleneck with a faster implementation. Don't try to do everything at once; get one thing working, then incrementally add and improve one step at a time.
Upvotes: 4
Reputation: 162327
OpenGL is very basic in what it offers you as graphic primitive. Everything more complex than a point, line or triangle, textured or not, must be implemented by the user.
I think the best course of action would be drawing small quads at the marker positions. Using instanced drawing and shaders this can be done very efficiently. Look for modern particle system rendering techniques to get the idea. The shape of a marker can be defined by either a texture, or, and that's what I'd do, procedurally in a fragment shader by solving for some equation that describes the marker shape, and discard
-ing all the fragments not part of the shape.
Upvotes: 1