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.