draw faster

Hi folks :slight_smile:

I’ve been working on a program that plots data points using OpenGL. Everything seems to work correctly, but the drawing is a bit slow ( probably due to the fact that I’m drawing about 20,000 points ) but that can’t be helped. I have to draw every data point that I receive from an outside file. But I was hoping that someone knew of something that I can do to speed up the drawing. I’ve thought of drawing to a bitmap first then displaying the bitmap once it’s finished but I’m not sure if that would really buy me anything. Plus, I don’t know how to handle bitmaps on OSs other than Microsoft Windows and this program has to work on multiple platforms. My code is below…there’s nothing fancy here. I’d appreciate any tips.
Thanks in advance.

… enable Depth Buffer in SetUp…
… A for loop goes through a linked list of data records, retrieves the datas X, Y values and sends these values to the function below to draw the point…

// Get supported point size range
glGetFloatv(GL_POINT_SIZE_RANGE, sizes );

// Set initial point size
cursize = sizes[1];

glPointSize( curSIze );

// Draw points

// Specify the color, point ,and move the Z value up a little
glColor3ub( (GLubyte)red, (GLubyte)green, (GLubyte)blue );
glVertex3f(x, y, z);
z += 0.5f;

// Done drawing points

// Flush drawing commands

…keeps going through the for loop and doing the above until it’s gone through all the data.

first off, your speed bottleneck might not be -just- the rendering. to check this, comment out all of the gl calls except for maybe a single point per frame.

in other words, send as little to the gl as you can, just enough to see it render, and see how fast it runs. if it’s still slow, it’s not the gl.

from the way you have the code posted, it looks like your calling the function for each point. that’s alot of parameter passing if you call the functino 20,000 times.

even if you inlined the function, it still is 20,000 * 3 floating point assigns…

have you looked int glDrawElements and vertex arrays?

all you have to do is pass the address of a linear list of vertex data. it will get rid of a lot of the overhead involved in calling your function (or even glVertex) 20,000 times

hope i am of service


It looks like Jade is using glPointSize for each point, which means the points can not be rendered in a single glBegin(GL_POINTS) (which glDrawElements / glDrawArrays do !). I don’t think there is a Point Size Array that could be used here…

Of course, Jade is always using the same point size (which is the min one returned by GL_POINT_SIZE_RANGE). If he (she?) wants to be able to modify the point size for each point, she (he?) can not use vertex arrays…

If the size should be the same for all the points, then you are right ! Go for vertex arrays… Using a display list might be a good idea as well !

Best regards.


P.S. : I am wondering if the GL_EXT_point_parameters works with vertex arrays…

Thanks for the tips.
I’ll see how it works with glDrawElements. I hadn’t thought about changing point size from what I set it to…but it might be a possibility in the future, so I’ll have to keep that in mind…here goes.