在搜索和阅读有关现代OpenGL的内容以升级我的现有项目后,我有点困惑,因为我的3D框架基于OpenGL 2.1。
所以,就我所学到的...
We need to generate our Vertex-Buffer-Objects from vertices, indices, normals, colors, uvs, etc.
then we can use GLM for matrix transformation, and we only use VBO to create or manipulate meshes, finally we pass everything into GLSL vertex shader like this...
glm::mat4 MVP = projection * view * model; glUniformMatrix4fv(glGetUniformLocation(shaderProgramID, "MVP"), 1, GL_FALSE, glm::value_ptr(MVP)); //or &MVP[0][0] // uniform mat4 MVP; // in vec3 Vertex; // void main(void) // { // gl_Position = MVP * vec4(Vertex, 1.0); //instead of ftransform(); // }
问题:如何在不使用pushMatrix/popMatrix的情况下进行分层变换?(或者我们可以通过使用VBO来进行分层变换,这是可能的吗?)
如果不可能,那么如何通过GLM和C++<stack>库实现与pushMatrix/popMatrix相同的结果?
假设我需要像这样的东西:
> Set identity
> Translate to X, Y, Z
> Draw Mesh 1
> Rotate 0.5 by X axis
> Draw Mesh 2
> Scale down to 0.1
> Draw Mesh 3