Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: How to draw points efficiently

  1. #1
    Newbie Newbie
    Join Date
    Jun 2017
    Posts
    1

    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!

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,167
    Quote Originally Posted by orsonl View Post
    It works but due to the large number of points the program is pretty slow. Is there a more efficient way to do this?
    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?

  3. #3
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,728
    The simplest option for optimizing glBegin/glEnd code is to move your glBegin/glEnd calls outside of a loop, like so:
    Code :
    // 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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •