本文介绍了用不同的缓冲区指数的OpenGL 2.1绘图对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我处理用OpenGL 2.1 OBJ文件。这是OBJ规格:
据认为,一脸表示为顶点/材质/在每个缓冲器正常那里顶点,纹理和法线是不同的,顶点的意思指数,纹理坐标和正常指数是不同的。

I'm dealing with OBJ file with OpenGL 2.1. This is OBJ spec: http://www.martinreddy.net/gfx/3d/OBJ.specAccording to that, a face is indicated as vertex/texture/normal where vertex, texture and normal are different, this mean index of vertex, texture coordinate and normal index in each buffers are different.

问:如何绘制提供不同的显示每个顶点,纹理和法线数组缓冲区对象

Question: How can i draw an object that supply different indicate buffers for each vertex, texture and normal arrays?

推荐答案

伤心的答案,这是不可能在OpenGL。在OpenGL(和许多其他类似的系统,特别是Direct3D的),顶点是概念上的所有顶点的联合属性,如位置,法线或纹理坐标(这是不幸的是,长期的顶点的往往只是使用对于位置属性)。因此两个顶点具有相同的立场,但不同的法向量的概念是两个不同的顶点。

Sad answer, this is not possible in OpenGL. In OpenGL (and many other such systems, especially Direct3D), a vertex is conceptually the union of all the vertex attributes, like position, normal or texture coordinates (it's unfortunate that the term vertex is often used only for the position attribute). So two vertices with the same position but different normal vectors are conceptually two different vertices.

这就是原因,你为什么要使用相同的顶点索引的所有属性。因此,要绘制OpenGL或类似的库一个obj文件,你就不会得到解决加载后处理数据。

That's the reason, why you have to use the same vertex index for all attributes. So to draw an .OBJ file with OpenGL or similar libraries, you won't get around processing the data after loading.

最简单的方法是完全删除索引,只是每个三角形角落里所有的顶点数据存储前一后,使用指数从脸部规范的阅读,因而具有 3 *˚F顶点并没有索引。然而这是相当低效的,因为你可能仍然有很多重复的顶点,即使考虑到在一个整体的所有属性。

The easiest way is to completely drop indices and just store all vertex data for each triangle corner one after the other, using the indices read from the face specification, thus having 3*F vertices and no indices. This, however is rather inefficient, since you probably still have many duplicate vertices, even if considering all attributes at a whole.

另一种选择是插入索引三元(由顶点,texcoord和正常指数)为哈希表,并将其映射到一个组合的索引。每当指数三已经存在,你在一个索引哈希表取代它,当它不存在,你添加一个新的顶点(包括位置,正常和texCoords)到您的最终渲染顶点数组,索引文件的使用索引三重顶点数组(并插入新的顶点数组的大小作为唯一索引哈希表,当然)。

Another option is to insert the index triples (comprised of vertex, texcoord and normal index) into a hash table and map it to a combined index. Whenever the index triple already exists, you replace it by the one index in the hash table and when it doesn't exist, you add a new vertex (comprised of position, normal and texCoords) to your final rendered vertex arrays, indexing the file's vertex arrays using the index triple (and insert this new vertex array size as unique index into the hash table, of course).

这篇关于用不同的缓冲区指数的OpenGL 2.1绘图对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 20:42