I am working on a little vector drawing app, and by vector, I don’t really mean the “vector” in the openGL sense, but in the sense that it is an app that displays vector data (i.e., even though the points are 3D - there are no quads, or triangles or any closed primitives - only points and lines.
What I am trying to figure out is the most efficient way of displaying both points and lines.
The data is coming from a proprietary file format that is super simple - it is nothing but a list of points, and each point has a color and a flag which specifies whether to draw a line from the previous pt. That’s it. Super Simple.
In this application, there will be a user option to turn on “points” so that not only are the lines drawn, but points are also drawn at each vertex that is connected to a visible line.
I have this working perfectly - using immediate mode and a very simple algorithm - here is the pseudo code:
glpointsize(2.0);
glenable(GL_POINT_SMOOTH); // I like them round!
for (i = 0; i < frame.points.length; i++) {
pt = frame.points[i];
if (pt.blanking) {
moveto(pt.x,pt.y,pt.z);
}
else {
glcolor(pt.color.red, pt.color.green, pt.color.blue);
lineto(pt.x, pt.y, pt.z);
if (showPoints) {
glbegin(GL_POINTS);
glvertex(pt.x, pt.y, pt.z);
glend();
}
}
}
glflush();
*Note: moveto() and lineto() are kinda like macro thingies that wrap a glbegin(mode);glvertex();glend(); together in a macro. My little app is implemented using Max/MSP Jitter jit.gl.sketch - which for those not familiar is a super simple way to get an openGL renderer up and running.
The problem is that this seems like a very inefficient way of showing points - it is doubling the number of vertices. Not only does it feel like it is inefficient, I notice a sharp drop in performance when showing points using this technique. Drawing an image with, say 5000 vertices and not showing points (just lines), I get buttery smooth fps ( > 60) - it has no problem drawing at whatever my drawing loop is set at - however, whenever I turn on showPoints - the fps drops in half, sometimes even down to like < 5 fps if there are a large number of points.
Here is a screen shot of a sample file being rendered with points.
[ATTACH=CONFIG]856[/ATTACH]
Why is there not a mode like GL_POINTS_AND_LINES?
Any help would be much appreciated…