2010-08-14 95 views
2

我使用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个VBO渲染1个多边形。我需要一种方法来修改上面的代码,以便它可以看起来更像这样:

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

我该怎么做?

回答

10

perticularly 1 VBO 1个多边形

哇。 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(); 

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

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

注意:I a假设三角形标签中的顶点以与我的图片相同的顺序存储,并且您希望三角形顶点按照逆时针顺序发送。如果你想要它们是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(); 
+0

By 1 vbo per polygon我的意思是一系列的三角形,对不起 – jmasterx 2010-08-14 21:25:13