What is gl_ModelViewMatrix and gl_ModelViewProjectionMatrix in modern OpenGL?

落花浮王杯 提交于 2019-12-03 08:07:31

I'm not too familiar with GLSL 3.3, but I bet that PerspectiveViewMatrix (is it even builin functionality?) constructs matrix that replaces old builtin gl_ProjectionMatrix

gl_ModelViewMatrix in general is the product of object's transformation matrix in world space and its own "local" transformation, so it can be defined as the product of TranslationMatrix, RotationMatrix and TransformationMatrix.


You need to send all the matrices to the shader yourself, e.g. as uniforms. These matrices you need to build yourself (e.g. using GLM). Lazy example for a projection matrix:

// in your app

std::array<GLfloat, 16> projection;

glMatrixMode(GL_PROJECTION);
glPushMatrix();
gluOrtho(...);
glGetFloatv(GL_PROJECTION_MATRIX, projection.data());
glPopMatrix();

glUniformMatrix4fv(glGetUniformLocation(ShaderProgramID, "ProjectionMatrix"), 1, GL_FALSE, projection.data());

// in vertex shader

uniform mat4 ProjectionMatrix;
in vec4 InVertex;

void main() {
    gl_Position = ProjectionMatrix * InVertex;
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!