【问题标题】:Rendering pyramid in openGL在openGL中渲染金字塔
【发布时间】: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);

我希望前三个点是三角形的正面,但出于某种原因,情况似乎并非如此。颜色不是预期的(每个顶点都有自己的颜色),而且金字塔顶部的高度甚至都不是。有人发现我的代码有问题吗?

【问题讨论】:

    标签: opengl rendering


    【解决方案1】:

    OpenGL 索引是从 0 开始的。有 5 个顶点,索引的范围必须是 0 到 4。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-07
      • 2023-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-04
      • 2017-07-01
      相关资源
      最近更新 更多