gpt4 book ai didi

c++ - 在 OpenGL 中生成网格

转载 作者:太空宇宙 更新时间:2023-11-04 13:52:13 24 4
gpt4 key购买 nike

我正在尝试使用 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 缓冲区大小设置为不正确的值,因此无法呈现,尽管网格生成例程运行良好。

关于c++ - 在 OpenGL 中生成网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23028891/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com