将三角形条转换为三角形?

我正在使用GPC曲面细分库,它输出三角形条带。 该示例显示如下呈现:

for (s = 0; s < tri.num_strips; s++) { glBegin(GL_TRIANGLE_STRIP); for (v = 0; v < tri.strip[s].num_vertices; v++) glVertex2d(tri.strip[s].vertex[v].x, tri.strip[s].vertex[v].y); glEnd(); } 

问题在于这会产生多个三角形条带。 这对我来说是个问题。 我的应用程序使用VBO渲染,特别是1个多边形的1个VBO。 我需要一种方法来修改上面的代码,以便它可以看起来像这样:

 glBegin(GL_TRIANGLES); for (s = 0; s < tri.num_strips; s++) { // How should I specify vertices here? } glEnd(); 

我怎么能这样做?

特别是1个多边形的1个VBO

哇。 每个多边形1个VBO效率不高。 杀死顶点缓冲区的全部原因。 顶点缓冲区的想法是尽可能多地将顶点填入其中。 您可以将多个三角形条带放入一个顶点缓冲区,或渲染存储在一个缓冲区中的单独基元。

我需要一种方法来修改上面的代码,以便它可以看起来像这样:

这应该工作:

 glBegin(GL_TRIANGLES); for (v= 0; v < tri.strip[s].num_vertices-2; v++) if (v & 1){ glVertex2d(tri.strip[s].vertex[v].x, tri.strip[s].vertex[v].y); glVertex2d(tri.strip[s].vertex[v+1].x, tri.strip[s].vertex[v+1].y); glVertex2d(tri.strip[s].vertex[v+2].x, tri.strip[s].vertex[v+2].y); } else{ glVertex2d(tri.strip[s].vertex[v].x, tri.strip[s].vertex[v].y); glVertex2d(tri.strip[s].vertex[v+2].x, tri.strip[s].vertex[v+2].y); glVertex2d(tri.strip[s].vertex[v+1].x, tri.strip[s].vertex[v+1].y); } glEnd(); 

因为triangletrip三角剖分是这样的(数字代表顶点索引):

 0----2 | /| | / | | / | |/ | 1----3 

注意:我假设三角形中的顶点以与我的图片中相同的顺序存储,并且您希望以逆时针顺序发送三角形顶点。 如果你想让它们成为CW,那么使用不同的代码:

 glBegin(GL_TRIANGLES); for (v= 0; v < tri.strip[s].num_vertices-2; v++) if (v & 1){ glVertex2d(tri.strip[s].vertex[v].x, tri.strip[s].vertex[v].y); glVertex2d(tri.strip[s].vertex[v+2].x, tri.strip[s].vertex[v+2].y); glVertex2d(tri.strip[s].vertex[v+1].x, tri.strip[s].vertex[v+1].y); } else{ glVertex2d(tri.strip[s].vertex[v].x, tri.strip[s].vertex[v].y); glVertex2d(tri.strip[s].vertex[v+1].x, tri.strip[s].vertex[v+1].y); glVertex2d(tri.strip[s].vertex[v+2].x, tri.strip[s].vertex[v+2].y); } glEnd();