PDA

View Full Version : vbo's = bad lighting



supagu
05-02-2004, 01:23 AM
okay, i have been using VBO's and the lighting of my models is a shocker.... incorect lighting.

so i tried rendering with glBegin(GL_TRIANGLES)
and it worked fine, so then i tried it with vertex arrays:
glDrawElements

and these also worked fine. so are VBO's buggy? or maybe im using them wrong?

heres how i use them:

glEnableClientState( GL_VERTEX_ARRAY );
glEnableClientState( GL_INDEX_ARRAY );

glBindBufferARB( GL_ARRAY_BUFFER_ARB, vboPositions );
glVertexPointer( 3, GL_FLOAT, sizeof(Vector3), 0 );

if( normals != 0 )
{
glEnableClientState( GL_NORMAL_ARRAY );
glBindBufferARB( GL_ARRAY_BUFFER_ARB, vboPositions );
glNormalPointer( GL_FLOAT, sizeof(Vector3), 0 );
}

if( uvCoords != 0 )
{
glClientActiveTexture( GL_TEXTURE0_ARB );
glBindBufferARB( GL_ARRAY_BUFFER_ARB, vboTexCoords );
glTexCoordPointer( 2, GL_FLOAT, sizeof(UVCoord), 0 );
glEnableClientState( GL_TEXTURE_COORD_ARRAY );

glActiveTextureARB( GL_TEXTURE0_ARB );
glEnable(GL_TEXTURE_2D);
}


glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, vboIndices );

glDrawElements(GL_TRIANGLES, noIndices, GL_UNSIGNED_INT, 0);


glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 );
glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, 0 );

glDisableClientState( GL_NORMAL_ARRAY );

glClientActiveTexture( GL_TEXTURE0_ARB );
glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 );
glDisableClientState( GL_TEXTURE_COORD_ARRAY );

glClientActiveTexture( GL_TEXTURE1_ARB );
glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 );
glDisableClientState( GL_TEXTURE_COORD_ARRAY );

glActiveTextureARB( GL_TEXTURE1_ARB );
glDisable(GL_TEXTURE_2D);
glActiveTextureARB( GL_TEXTURE0_ARB );
glDisable(GL_COLOR_ARRAY);


ideas? as i really wanna use vbo's for rendering due to speed.

3B
05-02-2004, 11:33 PM
if( normals != 0 )
{
glEnableClientState( GL_NORMAL_ARRAY );
glBindBufferARB( GL_ARRAY_BUFFER_ARB, vboPositions );
glNormalPointer( GL_FLOAT, sizeof(Vector3), 0 );
}i'm guessing you mean vboNormals or something instead of vboPositions?(or if you do have normals and positions in same vbo, you probably need to set the stride parameter to glVertexPointer/glNormalPointer differently, and need to set the offset param for whichever isn't at the beginning of the struct)