How to draw points efficiently

My program receives pcl pointcloud and plot each point one by one using:

glBegin(GL_POINTS);
glVertex3f(point.x, point.y, point].z);
glEnd();

It works but due to the large number of points the program is pretty slow. Is there a more efficient way to do this?
Thank you for your help!

Yes. Quite a few actually. You can get much faster than what you’ve got here.

A few prep questions:

  1. Are the point.xyz positions you render each frame the same ones every frame or different?
  2. If the latter, how do they change?
  3. What GPU and GPU GL driver do you have?
  4. Do you have any experience with OpenGL vertex arrays, vertex buffer objects, and/or display lists?

The simplest option for optimizing glBegin/glEnd code is to move your glBegin/glEnd calls outside of a loop, like so:

// this is slow
for (int i = 0; i < 10000; i++)
{
    glBegin (GL_POINTS);
    glVertex3f (x, y, z);
    glEnd ();
}

// this is fast
glBegin (GL_POINTS);

for (int i = 0; i < 10000; i++)
{
    glVertex3f (x, y, z);
}

glEnd ();

You will of course then be constrained by what is legal to call between glBegin and glEnd, but if this pattern fits your program then it’s worth doing; particularly if using non-static data because otherwise you would need to be careful about managing your VBO update(s) and have a risk of ending up even slower than you started out.