Jochem Van Der Spek
Jochem Van Der Spek

Reputation: 311

combining glVertexPointer and glVertexAttribPointer gives problems

I'm having an issue when first rendering a vertexbuffer with a program, and then rendering a different vertexbuffer without program.

for the first buffer, when a program is enabled, i use code similar to:

glBindBuffer( GL_ARRAY_BUFFER, m_id );
GLint location = glGetAttribLocation( pID, "position" );
glEnableVertexAttribArray( location );
glVertexAttribPointer( location, 3, GL_FLOAT, GL_FALSE, 3 * sizeof( GLfloat ), 0 );
glDrawArrays( m_mode, 0, m_numVertices );

for the second, without program:

glBindBuffer( GL_ARRAY_BUFFER, m_id );
glEnableClientState( GL_VERTEX_ARRAY );
glVertexPointer( 3, GL_FLOAT, 3 * sizeof( GLfloat ), 0 );
glDrawArrays( m_mode, 0, m_numVertices );

both codepaths work fine individually, but when done in the order "with program"->"without program", the second seems to use the buffer of the first, and in the order "without program"->"with program", the first is not drawn (in the second iteration).

now this suggests to me that I'm missing some state change done by the glEnableVertexAttribArray block, but I don't understand what state change is causing the problems.

ps the reason I'm rendering with and without program is that in the scenegraph lib im using you can turn programs on or off per node.

Upvotes: 4

Views: 2558

Answers (1)

datenwolf
datenwolf

Reputation: 162164

Try adding

glDisableVertexAttribArray( location ); // location of "position"

before switching to fixed function rendering.

Upvotes: 2

Related Questions