我无法让我的关卡数据出现在屏幕上。我有我的着色器在使用正确渲染一个立方体但不是水平。
这是我的 VBO、VAO 和 IBO 的设置:
void ZoneMesh::buildData()
{
// Create the VBO for this mesh
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
// Create the IBO
glGenBuffers(1, &ibo);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, numPoly * 3 * sizeof(short), indices, GL_STATIC_DRAW);
// Create the VAO
glGenVertexArraysAPPLE(1, &vao);
glBindVertexArrayAPPLE(vao);
// Bind the VBO to the buffer and set up the attributes
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), BUFFER_OFFSET(0));
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), BUFFER_OFFSET(sizeof(float)*3));
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), BUFFER_OFFSET(sizeof(float)*5));
//Bind the IBO to the VAO
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
}
这是我的顶点结构:
struct Vertex
{
float x;
float y;
float z;
float u;
float v;
float normX;
float normY;
float normZ;
};
以下是 ZoneMesh 类中的相关数据项:
Vertex* vertices;
short* indices;
GLuint vbo;
GLuint vao;
GLuint ibo;
顶点着色器:
#version 120
attribute vec3 position;
uniform mat4 camera;
void main()
{
gl_Position = camera * vec4(position, 1.0f);
}
片段着色器:
#version 120
void main(void)
{
gl_FragColor = vec4(0.0, 0.6, 0.7, 1.0);
}
渲染:
shader.Use();
// Testing - render the first 50 meshes
for(int i = 0; i < 50; i++)
{
glUniformMatrix4fv(shader("camera"), 1, GL_FALSE, glm::value_ptr(MVPMatrix));
glEnableVertexAttribArray(shader["position"]);
glBindVertexArrayAPPLE(zone.getVAO(i));
glDrawElements(GL_TRIANGLES, 500, GL_UNSIGNED_SHORT, NULL);
}
shader.UnUse();
渲染/着色器的使用不是问题。MVP 矩阵是正确的。我在其上方正确渲染了一个立方体。该区域不渲染。