PDA

View Full Version : gl*Pointer's with glinterleavedarray?



Vexator
11-04-2005, 11:25 AM
so far, i've been using seperate arrays for vertices, normals and uv-coordinates, like this:


on start up:

// Generate and bind buffers
glGenBuffers( 1, &Vertices.Id );
glBindBuffer( GL_ARRAY_BUFFER, Vertices.Id );
glBufferData( GL_ARRAY_BUFFER, ArraySize*sizeof(float)*3, Vertices.Data, GL_STATIC_DRAW );

glGenBuffers( 1, &Normals.Id );
glBindBuffer( GL_ARRAY_BUFFER, Normals.Id );
glBufferData( GL_ARRAY_BUFFER, ArraySize*sizeof(float)*3, Normals.Data, GL_STATIC_DRAW );

glGenBuffers( 1, &Coords.Id );
glBindBuffer( GL_ARRAY_BUFFER, Coords.Id );
glBufferData( GL_ARRAY_BUFFER, ArraySize*sizeof(float)*2, Coords.Data, GL_STATIC_DRAW );

render routine:

// Enable arrays and bind buffers
glEnableClientState( GL_VERTEX_ARRAY );
glBindBuffer( GL_ARRAY_BUFFER, Vertices.Id );
glVertexPointer( 3, GL_FLOAT, 0, 0 );

glEnableClientState( GL_NORMAL_ARRAY );
glBindBuffer( GL_ARRAY_BUFFER, Normals.Id );
glNormalPointer( GL_FLOAT, 0, 0 );

glEnableClientState( GL_TEXTURE_COORD_ARRAY );
glBindBuffer( GL_ARRAY_BUFFER, Coords.Id );
glTexCoordPointer( 2, GL_FLOAT, 0, 0 );

// Draw arrays
glDrawArrays( GL_TRIANGLES, 0, ArraySize );

// Disable arrays
glDisableClientState( GL_VERTEX_ARRAY );
glDisableClientState( GL_NORMAL_ARRAY );
glDisableClientState( GL_TEXTURE_COORD_ARRAY );

// Unbind buffers
glBindBuffer( GL_ARRAY_BUFFER, 0 );now i'm using a compiled array:


glInterleavedArrays( GL_T2F_N3F_V3F, 0, Array );
glDrawArrays( GL_TRIANGLES, 0, Size );but i'd like to use gl*Pointer's for my compiled array like i did before.. is this possible? the pointers have a stride option, but i don't get it how to use them in this case.. thx in advance :)

thanks :)

Zulfiqar Malik
11-04-2005, 12:12 PM
Suppose all your vertex data is within "data" pointer and your vertex strucure is defined as following:


struct VERTEX {
float pos[3];
float norm[3];
};Then you can bind your data as follows

// this is pseudo-code
glVertexPointer(..., stride = sizeof(VERTEX), data->pos);
glNormalPointer(..., stride = sizeof(VERTEX), data->norm);
// use glDrawArrays(...)