问题描述
我有这样的代码,它是上下文"#version 330 core"
I have this code which is context "#version 330 core"
gl_Position = PerspectiveViewMatrix(90.0, AspectRatio, 0.01, 1000.0 )
* TranslationMatrix(0, 0, -4 -0.35*MouseWheel)
* RotationMatrix(MouseMovement.y, X_AXIS)
* RotationMatrix(-MouseMovement.x, Y_AXIS)
* RotationMatrix(float(Strafing*3), Z_AXIS)
* TransformationMatrix
* in_Vertex;
其中哪一部分是旧的gl_ModelViewMatrix,哪一部分是gl_ModelViewProjectionMatrix? (用于创建ModelViewProjection的gl_ProjectionMatrix是什么?)
Which part of it is old gl_ModelViewMatrix and which part is gl_ModelViewProjectionMatrix? (What is gl_ProjectionMatrix that was used to create ModelViewProjection?)
推荐答案
我对GLSL 3.3不太熟悉,但是我敢打赌,PerspectiveViewMatrix(甚至还有builin功能?)构造的矩阵将替换旧的内置gl_ProjectionMatrix
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通常是对象在世界空间中的变换矩阵及其自身的局部"变换的乘积,因此可以将其定义为TranslationMatrix,RotationMatrix和TransformationMatrix的乘积.
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.
您需要自己将所有矩阵发送到着色器,例如作为制服.您需要构建自己的这些矩阵(例如,使用 GLM ).投影矩阵的懒惰示例:
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;
}
这篇关于在现代OpenGL中,gl_ModelViewMatrix和gl_ModelViewProjectionMatrix是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!