Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 3 123 LastLast
Results 1 to 10 of 21

Thread: GL_TRIANGLE_STRIP and VBO fail.

  1. #1
    Junior Member Newbie
    Join Date
    May 2012
    Posts
    10

    GL_TRIANGLE_STRIP and VBO fail.

    Hey!

    I have a big problem that I can't solve right now... I have searched all over the internet for hours... :-/

    Look at this picture:

    http://oi50.tinypic.com/v67rl4.jpg

    If I draw the terrain with Immediate mode:

    Code :
    for (int z = 0; z < DEPTH; z++)
    {
        glBegin(GL_TRIANGLE_STRIP);
        for (int x = 0; x < WIDTH; x++)
        {
            //Draw everything here...
        }
        glEnd();
    }

    Everything works just fine, no lines.

    But if i use just one interleaved VBO for colors, vertices and textures. Everything fail and end up with lines.

    I draw the terrain with glDrawArrays(GL_TRIANGLE_STRIP, 0, numberVertices).

    I know that glDrawArrays just draw all data.
    glDrawArrays + GL_TRIANGLE_STRIP = lines.
    glDrawArrays + GL_TRIANGLES = no lines. Terrain looks bad.

    I have the exact same problem as this guy: http://stackoverflow.com/questions/9...-drawing-error

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    896
    Please post a stripped down example showing buffer setup and rendering code.

  3. #3
    Advanced Member Frequent Contributor
    Join Date
    Jan 2007
    Posts
    965
    Is numberVertices == DEPTH * WIDTH? In other words, are you trying to draw multiple strips in a single call? If so, a single glDrawArrays with GL_TRIANGLE_STRIP won't work; your options are to either use primitive restart or GL_TRIANGLES (both of which will need indexes) or join your strips with degenerate triangles.

    Personally I'd use GL_TRIANGLES with indexes (via glDrawElements) for this; strips are just so 1998.

  4. #4
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    896
    Quote Originally Posted by mhagain
    strips are just so 1998
    this one made me smile.

  5. #5
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,171
    strips are just so 1998.
    What's wrong with strips?
    I've been using strips for years and IMHO they're more efficient than triangles as you only need to send 2 verticies/indicies per triangle comapred to 3.

  6. #6
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    896
    What's wrong with strips?
    What bothers me most about strips is that if you don't have a DDC Tool and exchange format which stores stripified geometry, you'll have to do the conversion from raw triangles or indexed geometry yourself and for most models it's not as simple as using the indexed geometry or removing doubles from a list of triangles and indexing yourself or as simple using strips for a regular grid or something. Do you proceed differently somehow?

  7. #7
    Advanced Member Frequent Contributor
    Join Date
    Jan 2007
    Posts
    965
    What's wrong with strips? Generally if someone like Tom Forsyth says something I tend to assume that the likelihood he knows what he's talking about is reasonably high, so here's what he has to say (link: http://tomsdxfaq.blogspot.com/)
    Let me say this just once, because academics are still spending time and money researching this subject. You're wasting your time. Strips are obsolete - they are optimising for hardware that no longer exists. Indexed vertex caches are much better at this than non-indexed strips, and the hardware is totally ubiquitous. Please go and spend your time and money researching something more interesting.
    http://home.comcast.net/~tom_forsyth...html#Strippers

    The ultimate stripper will get you one vertex per triangle. But even a very quick and dirty indexer will get you that, and a good indexer will get close to 0.65 vertices per triangle for most meshes with a 16-entry FIFO vertex cache.

  8. #8
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,171
    I think that the original post was with regard to a terrain - and that's where I'm coming from too. My terrains are a rendered by repeating a regular patch with a 'stitched' border between patches to avoid cracks. All of these are rendered using triangle strips and degenerate triangles.
    Since the actual rendering is done with indicides and draw elements, I wonder just how it could be more efficient with GL_TRIANGLES and indicies when, by definition, you are sending more indicies in the case of GL_TRIANGLES than for GL_TRIANGLE_STRIPS.
    For general purpose models, then yes, indexed triangles would be the way to go. For a regular grid - I don't think you can beat a Tri_strip as that's the best case scenareo.

  9. #9
    Junior Member Newbie
    Join Date
    May 2012
    Posts
    10
    Ok, so I should try degenerate triangles? Does anyone know any good tutorials?

  10. #10
    Advanced Member Frequent Contributor
    Join Date
    Jan 2007
    Posts
    965
    I'd personally use primitive restart rather than degenerates as it's just a single extra index. With degenerates you need to add extra vertexes, which can be done either via indexes (which is quite small overhead) or full fat vertexes (which can be a large overhead).

    As always with GPUs, what seems more intuitively faster in theory does not always turn out so in practice - witness the performance difference between GL_RGB and GL_BGRA texture formats, for example, despite the latter seeming to require more memory. So for a regular grid, using indexed triangles does have more indexes, yes, but it also allows you to remove more shared vertexes - the infinite regular grid case is the one that gets you 0.5 verts/tri which is the optimal case with indexes. Here's Tom F again:
    The theoretical limit for a regular triangulated plane with an infinitely large vertex cache is 0.5 verts/tri (think of a regular 2D grid - there's twice as many triangles as vertices)
    So it's quite clearly a balancing act - you accept more indexes in exchange for a greater reduction in vertexes, and come out of it on the right side of less data overall.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •