在OpenGL中将顶点阵列与纹理结合起来 [英] Combining vertex arrays with textures in OpenGL

查看:91
本文介绍了在OpenGL中将顶点阵列与纹理结合起来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用顶点数组绘制一个相当大的网格,其中包含大量的顶点.已经从这些纹理中确定了纹理,并且可以很容易地按照以下方式在即时模式下进行绘制:

I'm trying to use vertex arrays to draw a reasonably large mesh, containing a large number of vertices. The textures have been determined from these and it's easy enough to draw in immediate mode along the lines of:

glBegin(GL_TRIANGLES) {
  for ( int faceIdx = 0; faceIdx < nFaces; ++faceIdx )
     glVertex3fv(&vertexArray[vIdx]);
     glTexCoord2fv(&texCoord[vIdx++]);
     glVertex3fv(&vertexArray[vIdx]);
     glTexCoord2fv(&texCoord[vIdx++]);      
     glVertex3fv(&vertexArray[vIdx]);
     glTexCoord2fv(&texCoord[vIdx++]);  
  }   
} 
glEnd();

但是为了提高可读性,速度和其他方面,我想使用顶点数组(以转向VBO).有没有一种方法可以解决将单个顶点多次放入数组的问题?

However for readability, speed and the rest I want to use vertex arrays (with a view to moving to VBOs). Is there a way of getting around putting a single vertex into the array multiple times?

据我目前的了解,有必要指定网格的每个顶点与在网格的一个面中出现的次数一样多,因为每个顶点都可以标识多个纹理坐标(纹理是从真实世界中捕获的网格近似的对象的图像),即我的顶点/tex坐标数组的读取就像是在立即模式下填充它一样.

As I understand it at the moment it's necessary to specify each vertex of the mesh as many times as it appears in a face of the mesh, as each vertex identifies to multiple texture coordinates (the textures are captured from a real-world image of the object the mesh approximates), i.e. my vertex/tex coord array reads as if I'd filled it in immediate mode.

有什么方法可以在指定纹理坐标的同时使用顶点数组,而无需使用冗余(我的意思是重复的)顶点?

Is there any way to use vertex arrays, whilst specifying the texture coordinates, without using redundant (by which I mean repeated) vertices?

推荐答案

单个顶点由组成该单个顶点的所有属性组成.因此,共享相同位置但具有不同纹理坐标的两个顶点在概念上是不同的顶点.所以不,没有简单的方法可以为不同的texCoords重复顶点位置.

A single vertex is comprised of all attributes that make up this single vertex. So two vertices that share the same position but have different texture coordinates are conceptually different vertices. So no, there is no simple way around repeating vertex positions for different texCoords.

但是通常情况下,仅在某些罕见区域(例如锋利的边缘,由于不同的法线或在您的情况下是纹理接缝)才需要进行此类顶点复制.那么,您所有面孔的角部确实具有不同的texCoords吗?也许您可以对数据进行一些预处理,然后找到相邻的面,这些面共享 texCoords的位置,因此可以共享顶点.如果许多顶点不是这种情况,那我会感到惊讶,而您最终只会得到一小部分重复的顶点.

But usually such vertex duplications are only neccessary in some rare regions (like sharp edges, because of different normals, or like in your case a texture seam). So do all your faces' corners really have different texCoords? Maybe you can pre-process your data a bit and find neighbouring faces that share positions and texCoords and can therefore share the vertex. I would be suprised if that wouldn't be the case for many many vertices and you end up with only a small bunch of duplicated vertices.

这篇关于在OpenGL中将顶点阵列与纹理结合起来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆