I upload data to the VBO every loop because they are dynamic (stencil shadows).
I got it to work (with an improvement of about 25% respect to immediate mode) as it follows:
glColorMask(0, 0, 0, 0);
glStencilFunc(GL_ALWAYS, 1, 0xffffffff);
// 1st pass
glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(dati_ombra), dati_ombra, GL_DYNAMIC_DRAW_ARB); //swiched from STATIC to DYNAMIC
glVertexPointer( 3, GL_FLOAT, 0, (char ) NULL );
glDrawArrays(GL_QUADS, 0, polys_to_be_drawn4);
// 2nd pass
glStencilOp(GL_KEEP, GL_KEEP, GL_DECR);
glDrawArrays(GL_QUADS, 0, polys_to_be_drawn*4);
glDisableClientState( GL_VERTEX_ARRAY );
//draw a shadowing rectangle covering the entire screen
glStencilFunc(GL_NOTEQUAL, 0, 0xffffffff);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
glVertex3f( 0.1f, 0.1f,-0.10f);
glColorMask(1, 1, 1, 1);
Probably the code can be still optimized some more, but i’m not very experienced.
Also, i still have a problem with infinite shadow volumes: i cant set them up, i have read also some articles on Gamasutra but did not understand much of it. I’m going to ask this in a separate thread.