【问题标题】:Generating a grid in OpenGL在 OpenGL 中生成网格
【发布时间】:2014-04-12 10:02:37
【问题描述】:

我正在尝试使用 OpenGL 3+ 绘制网格。但是,我在生成它时遇到了问题。我的代码是:

vec3 *verts = new vec3[(resolution)*(resolution)];
int count = 0;
for(int i = 0;i<resolution;i++)
    for(int j = 0;j<resolution;j++)
    {
        verts[count++] = vec3(i,0,j);
    }

GLuint *indices = new GLuint[(resolution-1)*(resolution-1)*6];

count = 0;
for(int i = 0;i<resolution-1;i++)
{
   for(int j = 0;j<resolution-1;j++)
    {
        indices[count++] = i*resolution+j;
        indices[count++] = i*resolution+j+1;
        indices[count++] = (i+1)*resolution+j;
        indices[count++] = (i+1)*resolution+j;
        indices[count++] = i*resolution+j+1;
        indices[count++] = (i+1)*resolution+j+1;
    }
}

我将几何图形绘制为 GL_TRIANGLES 并没有看到任何东西。

【问题讨论】:

  • 为什么要把网格画成三角形?使用 GL_LINES
  • @willywonka_dailyblah,应该填满网格。实际上,我会在顶点着色器中置换顶点高度来绘制地形。顺便说一句,GL_LINES 无论如何都不起作用。
  • @RostakaGmfun:还有 GL_POINTS?如果没有,请发布您的绘图程序和着色器(如果有)。
  • @RostakaGmfun:这段代码有什么问题?它原则上应该起作用。所以错误可能在代码的其余部分。

标签: c++ opengl opengl-3


【解决方案1】:

最后,我发现了问题 - GL 缓冲区大小设置为不正确的值,因此未渲染,尽管网格生成例程运行良好。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-21
    • 2016-02-20
    • 2011-08-20
    • 2012-10-30
    • 1970-01-01
    相关资源
    最近更新 更多