.obj 中的面孔如何工作?

发布于 2024-10-05 10:51:14 字数 211 浏览 1 评论 0原文

解析具有顶点和顶点面的 .obj 文件时,可以轻松地将顶点传递给着色器并使用顶点面使用 glDrawElements。

当解析具有顶点和纹理坐标的 .obj 文件时,会出现另一种类型的面:纹理坐标面。

显示纹理时,除了加载图像、绑定图像并将纹理坐标传递给解析器之外,如何使用纹理坐标面? 它们与顶点面不同,我认为纹理坐标面在显示纹理时有一个目的?

问候尼古拉斯

When parsing an .obj-file, with vertices and vertex-faces, it is easy to pass the vertices to the shader and the use glDrawElements using the vertex-faces.

When parsing an .obj-file, with vertices and texture-coordinates, another type of face occur: texture-coordinate faces.

When displaying textures, apart from loading images, binding them and passing texture coordinates into the parser, how to use the texture-coordinate faces?
They differ from the vertex-faces and I suppose that the texture-coordinate faces have a purpose when displaying textures?

Regards Niclas

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深海夜未眠 2024-10-12 10:51:14

不确定你在问什么,但如果我理解正确的话,你想知道如何存储纹理坐标数据来渲染纹理 3D 对象。如果是这样,您可以将 vertex-normal-textureCooperative 数据存储为交错格式,如下所示:

vertexX vertexY vertexZ normalX normalY normalZ textureX textureY textureZ

一旦您拥有了这些数据的数组,您就可以创建指向该数组不同部分的指针并如下所示进行渲染:

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glVertexPointer(3, GL_FLOAT, sizeof(vertexArray[0])*9, &vertexArray[0]);
glNormalPointer(3, GL_FLOAT, sizeof(vertexArray[0])*9, &vertexArray[3]);
glTexCoordPointer(GL_FLOAT, sizeof(vertexArray[0])*9, &vertexArray[6]);

glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_SHORT, &indices[0]);

至少我是这样的我正在做。可能有更好的方法,如果有的话,我很高兴知道。

Not sure what you're asking, but if I understand you correctly, you're wondering how do you store the data for texture coordinates to render a textured 3d object. If so, you store your vertex-normal-textureCoordinate data in an interleaved format, like below:

vertexX vertexY vertexZ normalX normalY normalZ textureX textureY textureZ

once you have an array of these, you then create pointers to the different parts of the array and render like below:

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glVertexPointer(3, GL_FLOAT, sizeof(vertexArray[0])*9, &vertexArray[0]);
glNormalPointer(3, GL_FLOAT, sizeof(vertexArray[0])*9, &vertexArray[3]);
glTexCoordPointer(GL_FLOAT, sizeof(vertexArray[0])*9, &vertexArray[6]);

glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_SHORT, &indices[0]);

At least that is how I'm doing it. There may be a better way, and if there is, I'd be glad to know.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文