Results 1 to 2 of 2

Thread: Which code is faster?

  1. #1
    Senior Member Regular Contributor
    Join Date
    Dec 2002
    Posts
    120

    Which code is faster?

    1)
    int i=0;

    glBegin(GL_POINTS);
    for(i=0;i<numOfVertex;i++){
    glVertex3fv(&poly[i].x);
    }
    glEnd();
    for(i=0;i<numOfVertex-1;i++){
    glBegin(GL_LINES);
    glVertex3fv(&poly[i].x);
    glVertex3fv(&poly[i+1].x);
    glEnd();
    }

    2)
    for(i=0;i<numOfVertex-1;i++){
    glBegin(GL_POINTS);
    glVertex3fv(&poly[i].x);
    glEnd();

    glBegin(GL_LINES);
    glVertex3fv(&poly[i].x);
    glVertex3fv(&poly[i+1].x);
    glEnd();
    }
    glBegin(GL_POINTS);
    glVertex3fv(&poly[i].x);
    glEnd();

    At first i taught the 2nd one should be faster because only one loop. But when i try both of the code, the first one can render faster than the 2nd one. Does anyone know the reason?

  2. #2
    Senior Member Regular Contributor
    Join Date
    Apr 2003
    Location
    Toulouse, France
    Posts
    133

    Re: Which code is faster?

    the first code is faster because you call glBegin(...)/glEnd() less than in the second one.

    note that this code is faster:

    glBegin(GL_POINTS);
    for(i=0;i<numOfVertex;i++)
    {
    glVertex3fv(&poly[i].x);
    }
    glEnd();
    glBegin(GL_LINE_STRIP);
    for(i=0;i<numOfVertex;i++)
    {
    glVertex3fv(&poly[i].x);
    }
    glEnd();

Similar Threads

  1. Replies: 10
    Last Post: 05-24-2017, 07:31 PM
  2. Replies: 1
    Last Post: 12-06-2010, 10:39 AM
  3. Which one is faster?
    By aronsatie in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 09-03-2010, 06:21 AM
  4. Replies: 3
    Last Post: 05-12-2010, 04:09 PM
  5. Which is faster?
    By Osku in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 02-04-2001, 09:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean