Results 1 to 3 of 3

Thread: Efficient use of vertex arrays.

  1. #1
    Senior Member Regular Contributor
    Join Date
    Oct 2002
    Posts
    164

    Efficient use of vertex arrays.

    Hello.
    I want to start using vertex arrays and am not quite sure how to best use them.
    Code :
    static GLfloat g_cube_vertices[] = { 1.0f,  1.0f,  1.0f,  //0
    									-1.0f,  1.0f,  1.0f,  //1
    									 1.0f, -1.0f,  1.0f,  //2
    									-1.0f, -1.0f,  1.0f,  //3
     
    									 1.0f,  1.0f, -1.0f,  //4
    									-1.0f,  1.0f, -1.0f,  //5
    									 1.0f, -1.0f, -1.0f,  //6
    									-1.0f, -1.0f, -1.0f}; //7
     
     
    static GLubyte g_cube_strip[] = {0, 1, 2,
    								 3, 6, 7,
    								 3, 5, 1,
    								 0, 5, 4,
    								 0, 6, 3,
    								 7, 4, 5};
     
    //somewhere in the drawing funtion
    	glVertexPointer(3, GL_FLOAT, 0, g_cube_vertices);
    	glEnableClientState(GL_VERTEX_ARRAY);
     
    glDrawElements(GL_TRIANGLE_STRIP, 18, GL_UNSIGNED_BYTE, g_cube_strip);
    This will draw a cube. If I want to draw another cube I simply call glDrawElements again.
    Now, when I had never used the vertex array yet I had the impression that you would feed more or less all of your vertex data in the array and then draw it. Now I still draw every cube alone, so I cannot see why I should use it instead of display lists.
    Can you show the best way to draw more than 1 object, using the vertex array?
    Also I am very confused about how to apply textures, normals and other stuff to the array.
    Any help is very appreciated. Thanks.
    I may not be good looking but I sure am dumb.

  2. #2
    Senior Member Regular Contributor
    Join Date
    Nov 2002
    Location
    Vancouver, BC, Canada
    Posts
    118

    Re: Efficient use of vertex arrays.

    Check out http://www.cs.rit.edu/~ncs/Courses/5...LonWin-15.html for how to use VAs.

    You're on the right track. For drawing a simple cube chances are vertex arrays will be slightly worse than display lists.

    Of course you can use vertex arrarys in your display lists... But unless you use compiled VA's, or even better, nVidia's VAR or ATI's VAO, they might not match display lists for performance.

    The reason you would use a VA over a Display List is because once you've made a display list you can't change it. If you're doing skinning or normal mapping on older hardware (no ARB_vertex_program support) you have to manually change your verticies all the time, and VA's become your only option.

    Another reason may be for a particle system. Rather than using a matrix transform for each particle, just move each in a VA and then draw the entire array without push/popping a matrix for each particle.

    But for static geometry, like a cube or anymechanical object like a robot, Displays lists are awesome!
    http://www.fl-tw.com/opengl/GeomBench/ gives you an idea of what kind of performance to expect.

  3. #3
    Senior Member Regular Contributor
    Join Date
    Oct 2002
    Posts
    164

    Re: Efficient use of vertex arrays.

    Another reason may be for a particle system. Rather than using a matrix transform for each particle, just move each in a VA and then draw the entire array without push/popping a matrix for each particle.
    Yes! A particle system is excactly what I want to do. I think I understand the basic theory behind your suggestion but I am having a hard time to imagine what the actual code would look like.
    Any help here would be extremly cool!
    Thanks for your reply!


    [This message has been edited by B_old (edited 12-07-2002).]
    I may not be good looking but I sure am dumb.

Similar Threads

  1. arrays of arrays as vertex output/fragment input
    By tsojtsoj in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 05-17-2018, 08:02 PM
  2. Vertex Arrays, interleaved arrays, mouseMove func
    By Nibirue in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 02-13-2012, 11:17 AM
  3. Big problem show arrays with vertex arrays
    By Rondey in forum OpenGL: Basic Coding
    Replies: 13
    Last Post: 03-15-2009, 10:09 AM
  4. efficient vertex arrays without duplicating data?
    By chrisweaver in forum OpenGL ES
    Replies: 6
    Last Post: 12-20-2007, 09:03 AM
  5. Efficient vertex program texture projection?
    By Kaldaien in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 09-22-2004, 04:11 PM

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