Skip to main content
GameDev.net gamedev.net
🔒 Locked

VertexArrays Prob

Started by Xero-X2 Apr 27, 2004 at 9:38 PM 0 replies 300+ views
Original Post
Xero-X2
Xero-X2
Ive used Vertex arrays in the past but today when I set this up it dosn't work. perhapes im forgeting something or making a stupid mistake. I can't seem to find the problem. I would be greatful if you could take a look over the code and point out anything wrong. I have narrowed it down to drawing Vertices only. Array Setup code
float * VArray;

  void SetupVA()
  {
    VArray = new float[Faces * 3 * 3]; // Total Size = 3 dimentions per point, and 3 points per Face    
    for ( int x = 0; x < Faces; x++ )
    {
      VArray[( x * 9 )    ] = Vertices[Face[x].A].x;
      VArray[( x * 9 ) + 1] = Vertices[Face[x].A].y;
      VArray[( x * 9 ) + 2] = Vertices[Face[x].A].z;
      VArray[( x * 9 ) + 3] = Vertices[Face[x].B].x;
      VArray[( x * 9 ) + 4] = Vertices[Face[x].B].y;
      VArray[( x * 9 ) + 5] = Vertices[Face[x].B].z;
      VArray[( x * 9 ) + 6] = Vertices[Face[x].C].x;
      VArray[( x * 9 ) + 7] = Vertices[Face[x].C].y;
      VArray[( x * 9 ) + 8] = Vertices[Face[x].C].z;
    }
 }
  
Drawing code (glDrawArrays)
    glVertexPointer( 3, GL_FLOAT, sizeof( VArray[0] ), & VArray[0] );
    glEnableClientState( GL_VERTEX_ARRAY );

    glDrawArrays( GL_TRIANGLES, 0, Faces * 3 );
   
    glDisableClientState( GL_VERTEX_ARRAY );
  
Alternate Working Drawing Code (glBegin/glEnd)
    glBegin( GL_TRIANGLES );
    for ( int x = 0; x < Faces; x++ )
    {
      glVertex3fv( & Vertices[Face[x].A].x );
      glVertex3fv( & Vertices[Face[x].B].x );
      glVertex3fv( & Vertices[Face[x].C].x );
    }
    glEnd();
  
Other Notes:
  143 fps on glBegin/glEnd
   66 fps on NonWorking glDrawArrays

Polygons are drawn when using glDrawArrays but the Vertices is completely incorrect.
  
"I seek knowledge and to help those who also seek it" Edit: Code Tag changes [edited by - Xero-X2 on April 27, 2004 10:40:39 PM]
"I seek knowledge and to help those who also seek it"
Xero-X2
Xero-X2
ok problem solved. I really want to hit my self after this.

glVertexPointer( 3, GL_FLOAT, 0, & VArray[0] );
glVertexPointer( Size, Type, Stride, Array);

I didn''t properly remember the 3rd varible, being Stride.

"I seek knowledge and to help those who also seek it"
"I seek knowledge and to help those who also seek it"

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.