Alright. After many, many hours of testing and stuff, I've managed to solve the problem on my own.
My shaders use a projection matrix, a view matrix and a model matrix, all three responsible for the final vertex position in the world
gl_Position = projection_matrix * view_matrix * model_matrix * local_vertex_position;
When the GLDebugDrawer class uses their glBegin()/glEnd() directives, there's something like a fall back situation.
The model_matrix, defined by the specific model in its own model space, sums up with the model matrix internally used by old glBegin()/glEnd() like
gl_Position = projection_matrix * view_matrix * model_matrix * glBegin/glEnd-Modelmatrix * local_vertex_position
So the result will look like the image above:
- the object is rendered with his model_matrix given by the bullet engine
- the shapes and collision shapes are rendered with the previously uploaded model_matrix * glBegin/glEnd-Modelmatrix (so the translation/rotation is somewhat like doubled)
(Note: glPushMatrix() and glPopMatrix() in GLDebugDrawer won't help to discard the previously uploaded matrix.
I think, because these function calls don't change the shader but the old OpenGL matrix stack)
Solution is to discard the model_matrix by uploading an identity matrix, just before the draw calls with glBegin()/glEnd(). Something like:
glm::mat4 model_matrix = glm::mat4(); GLuint uniform_model_matrix = glGetUniformLocation(m_opengl->getShader("3DBasic"), "model_matrix"); glUniformMatrix4fv(uniform_model_matrix, 1, GL_FALSE, glm::value_ptr(model_matrix)); m_physics->m_dynamicsWorld->debugDrawWorld();
This results in something like multiplying with 1, so shader internal it's like:
gl_Position = projection_matrix * view_matrix * 1 * glBegin/glEnd-Modelmatrix * local_vertex_position
Now the OpenGL 1 (or 2) draw calls use ONLY their own model matrices.
Hope it's useful for other people.
Have a nice day,