tags:

views:

66

answers:

1

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

  }

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++)
  {


    //for (v= 0; v < tri.strip[s].num_vertices; v++)
    //glVertex2d(tri.strip[s].vertex[v].x, tri.strip[s].vertex[v].y);
    //verticies modified to work as triangles

  }
   glEnd();

How could I do this?

Thanks

+6  A: 

perticularly 1 VBO for 1 polygon

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:

This should work:

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

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

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

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();
SigTerm
By 1 vbo per polygon I mean series of triangles, sorry
Milo