将三角形条转换为三角形? [英] Convert triangle strips to triangles?

查看:174
本文介绍了将三角形条转换为三角形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是GPC曲面细分库,它输出三角形条。
示例显示如下:

I'm using the GPC tessellation library and it outputs triangle strips. The example shows rendering like this:

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

The issue is in the fact that this renders multiple triangle strips. This is the problem for me. My application renders with VBO's, perticularly 1 VBO for 1 polygon. I need a way to modify the above code so that instead it could look something more like this:

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

我该如何做?

推荐答案


perticularly 1 VBO for 1 polygon

perticularly 1 VBO for 1 polygon

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

Whoa. 1 VBO per polygon won't be efficient. Kills the whole reason for vertex buffer. The idea for vertex buffer is to cram as many vertices into it as you can. You can put multiple triangle strip into one vertex buffer, or render separate primitives that are stored in one buffer.


上面的代码,所以它可以看起来更像这样:

I need a way to modify the above code so that instead it could look something more like this:

这应该工作:

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三角剖分法是这样(数字代表顶点索引):

Because trianglestrip triangulation goes like this (numbers represent vertex indexes):

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

注意:我假设trianglestrips中的顶点存储在与我的图片相同的顺序,你想要三角形顶点以逆时针顺序发送。如果你希望他们是CW,那么使用不同的代码:

Note: I assume that vertices in trianglestrips are stored in the same order as in my picture AND that you want triangle vertices to be sent in counter-clockwise order. If you want them to be CW, then use different code:

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

这篇关于将三角形条转换为三角形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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