What to do when i have more than one MVP matrices?

Started by
1 comment, last by Dejan7 12 years, 1 month ago
Hello, i've been struggling with this for the past few days, any help would be welcome.

So basically - i have two elements, a cube and a triangle and i want to draw them both. That means that i will need 2 different MVP (model-view-perspective) matrices, right?
Ok, so i build these two like this:
-----
-----
glm::mat4 MVPC = Projection * View * ModelCube;
glm::mat4 MVPT = Projection * View * ModelTriangle;
-----

Now i need to send them to shader like this for example

glUniformMatrix4fv(MatrixID, 2, GL_FALSE, &MVP[0][0]);


But how do i build MVP out of MVPC and MVPT, i guess that i need to mix them somehow (i have 2 matrices, so 2 is the second parameter in glUniformMatrix4f)?

Thanks
Advertisement
Pass the MVPC matrix to your shader and use is as the MVP matrix. Draw the cube. Then pass the MVPT matrix to the shader using it as the MVP matrix and draw the triangle.
[s]Ahh i see, thanks a lot! I believe that now i just miss one last step to make it to work! In vertex shader i have something like this[/s]

#version 330 core
layout(location = 0) in vec3 cube;
layout(location = 1) in vec3 triangle;
uniform mat4 MVP;
void main(){
// Output position of the vertex, in clip space : MVP * position
gl_Position = MVP * vec4(cube,1) ;

}


[s]i still don't get the triangle, because i guess that vec3 triangle must go somehow into gl_position? How can i do that, it's not as simple as with MVPs, because i have 2 different vec3 inputs, one for cube, one for triangle?

I believe that when i learn how to do this i will finally be able to draw both cube and a triangle! Damn you openGL, i spent two days struggling with such trivial thing![/s]



EDIT HELL YEAHH IT WORKS, i am stupid!!1 I didn't know that VBOs can have same attributes!!! sad.png So after i use the VBO for cube, i disable it, then assign the same VBO to triangle (0) and therefore i have only one vec3 input in GSGL:


#version 330 core
layout(location = 0) in vec3 object;
uniform mat4 MVP;
void main(){
// Output position of the vertex, in clip space : MVP * position
gl_Position = MVP * vec4(object,1) ;

}



Ah openGL, you can be so unfriendly to noobs like me sad.png

Thanks again foxfire92!!!

This topic is closed to new replies.

Advertisement