OpenGL drawing w/ Arrays or not?

This is a discussion on OpenGL drawing w/ Arrays or not? within the Game Programming forums, part of the General Programming Boards category; Open GL beginner here.. i was just wondering if there is a preferred way to draw geometry.. I've been working ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    93

    Question OpenGL drawing w/ Arrays or not?

    Open GL beginner here.. i was just wondering if there is a preferred way to draw geometry.. I've been working through the first 12 or so tutorials at NeHe and the way that they say to draw geometry is by typing:

    Code:
    glBegin(GL_TRIANGLES);
      glColor3ub(255, 0, 0);
      glVertexf(-1.0, 0.0, 0.0);
    
      glColor3ub(0, 255, 0);
      glVertexf(1.0, 0.0, 0.0);
    
      glColor3ub(0, 0, 255);
      glVertexf(0.0, 1, 0.0);
    glEnd();
    However I have read somewhere that using arrays may speed up things because there is less function calls and it groups all data together?!? Though it just said it might speed up a little. Just wondering how everyone draws their geometry.. I don't want to learn bad habits by using the "wrong"/"slower" way..

    Example of arrays:
    Code:
    static GLubyte colors[] = {255, 0, 0,
                                             0, 255, 0,
                                             0, 0, 255};
    static GLfloat vertices[] = {-1.0, 0.0, 0.0,
                                               1.0, 0.0, 0.0,
                                               0.0, 1.0, 0.0};
    
    glEnable(GL_VERTEX_ARRAYS);
    glEnable(GL_COLOR_ARRAYS);
    
    glColorPointer(3, GL_UNSIGNED_BYTES, 0, colors);
    glVertexPointer(3, GL_FLOAT, 0, vertices);
    
    glDrawArrays(GL_TRIANGLES, 3, ?, ?) // Can't remember last 2 params off the top of my head.
    
    glDisable(GL_VERTEX_ARRAYS);
    glDisable(GL_COLOR_ARRAYS);
    so which choice would be better/faster? also if arrays are better.. is it better to use separate arrays for colors/vertex/normals/etc.. or mash them into one large array(intertwined)?

    thnx in advance for any help...
    Last edited by tegwin; 01-14-2003 at 11:52 AM.

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    I'll give you a Performance FAQ from the OpenGL SDK. This will answer your questions.

    Note: I bet a lot of people would find this useful? Sticky?
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    93

    Talking Yes

    Yes that is very very useful.. just what I needed.. thnx mate.. good reference sheet..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can you make games without drawing in OpenGL?
    By Jake.c in forum Game Programming
    Replies: 9
    Last Post: 02-11-2009, 09:00 AM
  2. drawing my ui (openGL)
    By hannibar in forum Game Programming
    Replies: 1
    Last Post: 04-12-2006, 07:24 AM
  3. Why only 32x32? (OpenGL) [Please help]
    By Queatrix in forum Game Programming
    Replies: 2
    Last Post: 01-23-2006, 01:39 PM
  4. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  5. Pause in OpenGL, but don't stop drawing... ?
    By Arker in forum Game Programming
    Replies: 4
    Last Post: 10-16-2003, 10:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21