【发布时间】:2015-10-13 02:47:29
【问题描述】:
我正在尝试在 openGL 中渲染金字塔作为基本练习,但顶点的位置未按预期渲染。我希望金字塔以世界坐标系为中心,我使用的点就是这样。
glm::vec3 pos0(-width/2, -height/2, width/2); //front left vertex
glm::vec3 pos1(width/2, -height/2, width/2); //front right vertex
glm::vec3 pos2(-width/2, -height/2, -width/2);//back left vertex
glm::vec3 pos3(width/2, -height/2, -width/2); //back right vertex
glm::vec3 pos4(0.0f, height/2, 0.0f); //top vertex
我正在按此顺序使用 GL_DRAW_TRIANGLES 绘制金字塔,并将 CCW 显示为正面。
indices.push_back(5); /////////// front face
indices.push_back(2);
indices.push_back(1);
indices.push_back(5); /////////// left face
indices.push_back(3);
indices.push_back(1);
indices.push_back(5); /////////// back face
indices.push_back(3);
indices.push_back(4);
indices.push_back(5); /////////// right face
indices.push_back(4);
indices.push_back(2);
indices.push_back(1); /////////// left bottom
indices.push_back(3);
indices.push_back(2);
indices.push_back(2); /////////// right bottom
indices.push_back(3);
indices.push_back(4);
我希望前三个点是三角形的正面,但出于某种原因,情况似乎并非如此。颜色不是预期的(每个顶点都有自己的颜色),而且金字塔顶部的高度甚至都不是。有人发现我的代码有问题吗?
【问题讨论】: