Results 1 to 2 of 2

Thread: nature of VBOs

  1. #1
    Newbie Newbie
    Join Date
    Oct 2012

    Question nature of VBOs

    Hello everyone.

    I am fairly new to opengl and I've used it so with far with C for rendering 2D sprites in immediate mode. I have looked over VBOs
    a bit and it appears that everything in the VBO is drawn at once (possibly in parallel by all available graphics cores). It seems
    to me that this is exponentially more efficient than anything I'm doing.

    My questions are:
    1. Can individual elements in a VBO (like the nth 'rotation' float in the VBO) be modified in my 'animate' and 'detect_collisions' functions or are all of these changed at once. (see below).
    2. How should I set up my structs to easily fill in the VBO in say a create_VBO_from_sprites(sprite_Array) function.

    Here's the basic setup I'm using which works well so far on even weaker laptops with integrated GPUs:

    a sprite is defined:

    Code :
    typdef struct
       Texture* image;
       GLfloat width;
       GLfloat height;
       GLfloat xcoords[4];  // x vertices
       GLfloat ycoords[4];  // y vertices
       GLfloat rotation;      // in degrees
       GLfloat xdir;            // direction of travel x
       GLfloat ydir;            // direction of travel y

    In my idle function, I go through all sprites and do
    Code :
    //get start time 't0'
    // get time 't1' = time since 't0'
    // get difference 'gap' between 't1' and wanted refresh of 16.667 mlsec (60 frames per second)

    This basically just updates the vertices 'xcoords', 'ycoords' based on new values of 'rotation', 'xdir' and 'ydir'. If a
    collision is detected, the values of 'rotation', 'xdir', and 'ydir' are all changed based on some physics I will not write

    My display function simply draws the textures based on the 'xcoords' and 'ycoords' settings

    Code :
    for(GLuint i=0; i<sizeof(sprite_Array); i++)
       Sprite* sp = sprite_Array[i];
       glBindTexture(GL_TEXTURE_2D, sp->image->ID);
       glColor4f(1, 1, 1, sp->alpha);
       glTexCoord2i(0, 0); glVertex2f(sp->xcoords[0], sp->ycoords[0]);
       glTexCoord2i(1, 0); glVertex2f(sp->xcoords[1], sp->ycoords[1]);
       glTexCoord2i(1, 1); glVertex2f(sp->xcoords[2], sp->ycoords[2]);
       glTexCoord2i(0, 1); glVertex2f(sp->xcoords[3], sp->ycoords[3]);

  2. #2
    Yes, you can edit individual elements in a VBO. See glBufferSubData. There is also glMapBuffer and glUnmapBuffer.
    Also glMapBufferRange.
    There is an extensive page in the Wiki

    You can draw from any part of a VBO. It is your choice.

    Why store rotation in a VBO? It looks like you aren't using shaders. If you write a shader and decide to rotate your vertex in your vertex shader, then it makes sense to have a rotate value in your VBO.

    Normally, people declare a vertex structure. See

    the part that starts with
    struct Vertex { GLfloat position[3];

Similar Threads

  1. Some Help With VBOs
    By Fezziwig in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 04-08-2013, 06:07 AM
  2. Use of VBOs
    By GarrickW in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 10-22-2011, 12:42 AM
  3. The nature of GL_POINT
    By sasmaster in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 04-07-2011, 03:12 AM
  4. Replies: 5
    Last Post: 11-02-2010, 09:25 AM
  5. Two VBOs at once?
    By strattonbrazil in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 11-01-2010, 07:25 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