我似乎无法让我的 Square 进入正确的查看矩阵,以便使用glm
函数对其进行操作。
这基本上是我main.cpp
的,其中包括init()
加载纹理、glsl vert/frag 文件并从ground class
. 还有一个reshape()
anddisplay()
函数调用drawGround()
它来渲染实际的正方形。
在里面drawGround()
我添加了模型/视图矩阵并做了一个小翻译,但它不起作用......我已经玩了几个小时,似乎无法让它工作......
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
drawGround();
glUseProgram(0);
}
void drawGround(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUseProgram(myShader.handle());
GLuint matLocation = glGetUniformLocation(myShader.handle(), "ProjectionMatrix");
glUniformMatrix4fv(matLocation, 1, GL_FALSE, &ProjectionMatrix[0][0]);
glm::mat4 viewingMatrix = glm::translate(glm::mat4(1.0),glm::vec3(0,0,-1));
ModelViewMatrix = glm::translate(viewingMatrix,glm::vec3(15.0,0.0,0));
glUniformMatrix4fv(glGetUniformLocation(myShader.handle(), "ModelViewMatrix"), 1, GL_FALSE, &ModelViewMatrix[0][0]);
ground.render(texName, &myShader);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
glUseProgram(0);
}
然而在我的另一个程序上,我有以下功能renderSky()
很好。请帮我弄清楚我哪里出错了...如果您需要查看地面课程,请告诉我。
void renderSky(){
glUseProgram(mySkyShader.handle());
GLuint matLocation = glGetUniformLocation(mySkyShader.handle(), "ProjectionMatrix");
glUniformMatrix4fv(matLocation, 1, GL_FALSE, &ProjectionMatrix[0][0]);
glm::mat4 viewingMatrix = glm::translate(glm::mat4(1.0),glm::vec3(0,0,-1));
ModelViewMatrix = glm::translate(viewSkyMatrix,glm::vec3(15,0,0));
glUniformMatrix4fv(glGetUniformLocation(mySkyShader.handle(), "ModelViewMatrix"), 1, GL_FALSE, &ModelViewMatrix[0][0]);
skyBox.render();
glUseProgram(0);
}
这是顶点着色器:
#version 150
in vec3 in_Position;
in vec4 in_Color;
out vec4 ex_Color;
in vec2 in_TexCoord;
out vec2 ex_TexCoord;
void main(void)
{
gl_Position = vec4(in_Position, 1.0);
ex_Color = in_Color;
ex_TexCoord = in_TexCoord;
}