Results 1 to 3 of 3

Thread: Normal Pointer Array Size

  1. #1
    Junior Member
    Join Date
    Jun 2009
    Posts
    2

    Normal Pointer Array Size

    Hi
    Here is a strange one.
    I am developing a iPhone 3D engine and have a question about the normal pointer array.

    If I create an array that is the same size as the vertex array then my app crashes. If I make it double the size then all is OK. Can anyone explain this behaviour?

    ...
    vertices = new GLfloat[numvertices * 3];
    normals = new GLfloat[numvertices * 6];//Using 3, 4 or 5 the app crashes
    glEnableClientState( GL_VERTEX_ARRAY );
    glEnableClientState( GL_NORMAL_ARRAY );
    glVertexPointer( 3, GL_FLOAT, 0, vertices );
    glNormalPointer( GL_FLOAT, 0, normals );
    ...

    ...
    vertices[id] = pt->x; vertices[id] = pt->x; vertices[id] = pt->x;
    normals[id] = normal->x; normals[id] = normal->x; normals[id] = normal->x;
    id += 3;
    ...

    ...
    glDrawArrays( GL_TRIANGLES, 0, id );

    Cheers Nik

  2. #2
    Junior Member
    Join Date
    Mar 2009
    Location
    Redmond, Wa
    Posts
    13

    Re: Normal Pointer Array Size

    Maybe I'm looking at it wrong, but shouldn't the last parameter to glDrawArrays() be the number of vertices you want to draw, not the number of elements in your vertex array?

    For example: glDrawArrays( GL_TRIANGLES, 0, numvertices );

  3. #3
    Junior Member
    Join Date
    Jun 2009
    Posts
    2

    Re: Normal Pointer Array Size

    I understand - since a normal is 3 floats and my vertices use 3 floats in the call to glVertexPointer. The value count in the call to glDrawArrays is how many vertices to draw ie in my code (id/3), not always numvertices this is simply the size of the biggest mesh. I amended the code and all is working fine. I should have sussed this but thanks for the advice it was driving me mad.

Similar Threads

  1. Replies: 2
    Last Post: 08-13-2010, 03:09 AM
  2. Replies: 1
    Last Post: 05-16-2010, 09:24 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
  •