3D programming is great, but when something goes wrong, it can be quite hard to debug!
I was trying to launch two different OpenGL programs one after another, the first for the normal rendering, the second for a post-processing effect (motion blur, etc.). It seemed the first program's output was cleared as soon as the second one was activated.
I eventually found a behavior that is well summed up at http://www.gamedev.net/topic/541571-glsl-changing-between-shaders/page__view__findpost__p__4495411.
You don't write:
glUseProgram( shader-A ); modelA->Draw(); glUseProgram( shader-B ); modelB->Draw(); glutSwapBuffers();
modelA->Draw(); glUseProgram( shader-B ); modelB->Draw(); glUseProgram( shader-A ); glutSwapBuffers();
and since the code is called multiple times (at each frame), this will cycle OK. (There seem to be an GL_INVALID_OPERATION error the very first time I call glUseProgram, too.)
Anybody has an idea on why we have this behavior?