
我什么都试过了,我知道我的程序画的是正确的顶点,我基本上把它指向索引,下面是my循环
void mainLoop() {
while (!glfwWindowShouldClose(window)) {
glfwSwapBuffers(window);
glEnable(GL_DEPTH_TEST);
glClearColor(0.1, 0.1, 0.3, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glfwPollEvents();
glFrontFace(GL_CW);
glDisable(GL_CULL_FACE);
glfwGetFramebufferSize(window, &WIDTH, &HEIGHT);
glViewport(1, 1, WIDTH, HEIGHT);
glm::mat4 view = glm::lookAt(
glm::vec3(1.2f, 1.2f, 1.2f),
glm::vec3(0.0f, 0.0f, 0.0f),
glm::vec3(0.0f, 0.0f, 1.0f)
);
glm::mat4 projectionmatrix = glm::perspective(glm::radians(45.0f), 800.0f / 800.0f, 1.0f, 10.0f);
glm::mat4 identitymatrix = glm::mat4(1.0f);
glm::mat4 modelmatrix = identitymatrix;
MVPmatrix = projectionmatrix * view * modelmatrix;
GLint loc = glGetUniformLocation(SHADERPROGRAM, "MVPmatrix");
glUniformMatrix4fv(loc, 1, GL_FALSE, &MVPmatrix[0][0]);
short vertex_index[] = { 2U, 4U, 1U, 8U, 6U, 5U, 5U, 2U, 1U, 6U, 3U, 2U, 3U, 8U, 4U, 1U, 8U, 5U, 2U, 3U, 4U, 8U, 7U, 6U, 5U, 6U, 2U, 6U, 7U, 3U, 3U, 7U, 8U, 1U, 4U, 8U };
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(vertex_index) * sizeof(unsigned short), &vertex_index[0], GL_STATIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, temp_vertices.size() * sizeof(glm::vec3), &temp_vertices[0], GL_STATIC_DRAW);
glUseProgram(SHADERPROGRAM);
glDrawElements(GL_TRIANGLES, sizeof(vertex_index) , GL_UNSIGNED_SHORT, (void*)0);
}
}我真的不知道在这一点上,我已经尝试了很长时间。索引直接来自obj文件,顶点也是如此。此外,我试图关闭剔除,但没有成功,我也尝试添加手动指数数额,甚至试图抵消它们。
导入多维数据集的verts非常好,但只要我尝试制作一个索引多维数据集,就可以了。
发布于 2019-02-02 09:58:50
我取了OP提供的值,并画了一个草图:

然后我为它创建了顶点索引,得到:
GLushort vertex_index[] = {
0, 1, 2, 2, 3, 0, // front
0, 4, 5, 5, 1, 0, // right
4, 7, 6, 6, 5, 4, // back
7, 3, 2, 2, 6, 7, // left
0, 3, 7, 7, 4, 0, // bottom
1, 5, 6, 6, 2, 1 // top
};如果我没有犯任何错误(我仔细地保持三角形的方向在脑海中),这甚至应该与背面裁剪(只呈现特定常规武器方向的三角形)显示在立方体之外。
https://stackoverflow.com/questions/54491216
复制相似问题