Results 1 to 5 of 5

Thread: confused by vertex and index arrays!

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2004
    Location
    China P.R
    Posts
    9

    confused by vertex and index arrays!

    hi, i am currently trying to render a mesh model, i use the float pointer *pVertex to point to the triangle vertex array, and the GLuint pointer *pIndex to point to the triangle index array, the rendering code below works quite well:

    glBegin(GL_TRIANGLES);
    for (int i=0; i [LESS THAN] iTriangleCount; i++)
    {
    GLuint index1 = pIndex[3*i];
    GLuint index2 = pIndex[3*i+1];
    GLuint index3 = pIndex[3*i+2];

    glVertex3f(pVertex[5*index1],
    pVertex[5*index1+1],
    pVertex[5*index1+2]);
    glVertex3f(pVertex[5*index2],
    pVertex[5*index2+1],
    pVertex[5*index2+2]);
    glVertex3f(pVertex[5*index3],
    pVertex[5*index3+1],
    pVertex[5*index3+2]);
    }
    glEnd();

    One thing to explain is that for each vertex, 2 floating numbers are stored after the 3 coordinate values, that's why there is a "5" in the code.

    However, when I use the code below, rendering results turn out to be a mess:

    glVertexPointer(3, GL_FLOAT, 2*sizeof(GLfloat),
    pVertex);
    glEnableClientState(GL_VERTEX_ARRAY);

    glDrawElements(GL_TRIANGLES,
    3 * iTriangleCount,
    GL_UNSIGNED_INT, pIndex);

    glDisableClientState(GL_VERTEX_ARRAY);

    Could anybody tell me what the problem is? Thanks so much!!

  2. #2
    Junior Member Newbie
    Join Date
    Feb 2004
    Location
    Denver, CO
    Posts
    24

    Re: confused by vertex and index arrays!

    i guess your problem is your '5'. By default, the vertexpointer is expecting an x,y,z array, not x,y,z,s,t or something.

    There is a function to tell GL what the interleave is between to vertices, but i can't really remember. Something with pack or so?

    Anyone?

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2004
    Location
    Denver, CO
    Posts
    24

    Re: confused by vertex and index arrays!

    never mind me, it's of course the '2*sizeof(GLfloat)' you have in the code...

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: confused by vertex and index arrays!

    The stride parameter should be 5*sizeof(GLfloat), since you have 5 floats from the start of one vertex to the start of the next vertex.

  5. #5
    Junior Member Newbie
    Join Date
    Feb 2004
    Location
    China P.R
    Posts
    9

    Re: confused by vertex and index arrays!

    problem settled, thanks Bob!!

Similar Threads

  1. Multiple index lists for vertex arrays?
    By halo in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 12-18-2003, 12:39 AM
  2. index vertex arrays & tex-coords
    By McZ in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 03-05-2003, 06:28 AM
  3. vertex/texcoord/index/normal arrays
    By Structural in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 12-11-2002, 04:46 AM
  4. Using Index vertex arrays with Tex Coords
    By vonsatan in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 08-06-2001, 05:23 AM
  5. Frustum Culling with a set of Index Vertex Arrays?
    By Pete Bassett in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 01-14-2001, 08:18 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