在OpenGL中生成网格

罗斯塔卡·姆芬

我正在尝试使用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缓冲区的大小设置为不正确的值,因此未呈现。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章