Results 1 to 7 of 7

Thread: Vertex Buffer Object and Indices

  1. #1
    Member Contributor
    Join Date
    Jun 2009
    Posts
    90

    Vertex Buffer Object and Indices

    I currently store all my vertices in an array[vertices*3].
    I then store a normal for each vertex in an array[vertices*3].
    Finally, I have a given list of indexs cooresponding to the vertex. I am trying to use the index in a VBO in order to render.


    My problem is, I believe, in the indices. Initially I am given a list of 10,000 vertices, each structure has an XYZ coordinate.
    When I add this to the array[vertices*3], I insert array[0]=vertex0.x, array[1]=vertex0.y, array[2]=vertex0.z, etc...

    Now my initial indices don't index directly to the vertices? An example is instead of the index 1 referencing the 2nd vertex it will reference the y coordinate of vertex0...

    Why is this confusing me? Any help would be greatly appreciated!

  2. #2
    Senior Member Regular Contributor
    Join Date
    Aug 2003
    Location
    Toronto, Canada
    Posts
    162

    Re: Vertex Buffer Object and Indices

    When you setup your vertex array using glVertexPointer, you give a size parameter. GL uses this to know how many values to jump forward for each index.
    So you'd give a size of 3 to glVertexPointer, and so index 0 would reference array[0], and index 1 will reference array[3].
    Different attributes can have different sizes, and the index will still work correctly.

  3. #3
    Member Contributor
    Join Date
    Jun 2009
    Posts
    90

    Re: Vertex Buffer Object and Indices

    glVertexPointer(3, GL_FLOAT,3*sizeof(float), NULL);
    That is called the stride, correct? If this is set correctly, when I view my model as only points, all the points show up correctly. The problem when connecting these is madness. Does this implicitly mean error in my indices? Or how I set up the indices in the c++ code?

    Thanks for the quick response before!

  4. #4
    Senior Member Regular Contributor
    Join Date
    Aug 2003
    Location
    Toronto, Canada
    Posts
    162

    Re: Vertex Buffer Object and Indices

    Well its a combination of the stride and the size, depending on their values.
    A stride of 0 is the same as a stride of (size * sizeof(thedatatype)). 0 is a special value which means the value are tightly packed (stride = size * sizeof(thedatatype)).

    If you have some other stride (like if your data is in a single array, vx, vy, vz, nx, ny, nz), then it'll jump forward 'stride' bytes every index.

    It does sound like the issue is the connectivity, since the points are rendering correctly.

  5. #5
    Member Contributor
    Join Date
    Jun 2009
    Posts
    90

    Re: Vertex Buffer Object and Indices

    Can you look these two screenshots over:






    As you can see the points are where they should be! Luckily! But the problem arises from connecting them. Since I'm pretty new to openGL I could go for any suggestions on debugging this. I don't know how the indices themselves could be wrong, MATLAB uses them to render points.

  6. #6
    Member Contributor
    Join Date
    Jun 2009
    Posts
    90

    Re: Vertex Buffer Object and Indices

    *Solved*

    MATLab indices start at 1, not 0.

    I hope this can help someone in the future from a terrible annoyance!

  7. #7
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: Vertex Buffer Object and Indices

    Nice! I was short of ideas...

Similar Threads

  1. Vertex Array Object and vertex buffer object
    By Xxacero in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 07-23-2015, 05:13 AM
  2. Vertex Array Object vs. Vertex Buffer Object
    By michaelglaz in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 11-26-2014, 02:52 PM
  3. Texture Buffer Object shared with Vertex Buffer Ob
    By marshats in forum OpenGL: GLSL
    Replies: 3
    Last Post: 09-06-2010, 09:01 AM
  4. Vertex Buffer object
    By Janani in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 11-06-2009, 04:06 AM
  5. Vertex Buffer Object
    By Janani in forum OpenGL: Linux
    Replies: 0
    Last Post: 11-05-2009, 09:43 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