I tried writing a practice program which is used to draw massive cubics using instance tech. I learnt it from here: http://sol.gfxile.net/instancing.html
I sent a matrix to vertex_shader as an attribute by using glVertexAttribPointer, and it works as expected. However, when I comment this matrix in the vertex shader , and instead used gl_ModelViewProjectionMatrix itself, it’s failed to draw anything.
Actually the matrix I sent to the vertex_shader is an indentity matrix. It won’t affect anything to the result.
So I want to ask why ? Must I use the attribute in the shader which is sent from the host program?
The more usual way is to use the instancing data to create a unique modelview matrix, which is in turn used to calculate the MVP. The way your doing it is after you’ve already created a MVP.
Instead you need to supply your own separate projection, model and camera matricies. The model matrix is comming from your vertex attribute, per instance, so the code would be something like:
The key here then is to ensure your camera matrix contains just that - just the camera and nothing to do with models. In other words if your are making use of OpenGL’s modelView matrix, then avoid glTranslatef,glRotatef commands as they will be adding model parts to the modelview matrix.