0

I would like to follow up on this question, except that I have no code to show, so I decided to ask it here.
In the linked question, the OP was looking for an algorithm which could generate a plane with only one OpenGL triangle strip. He came up with a solution that works almost perfectly:

The order of the vertices for the strip is indicated by the arrows: 1-5-2-6-3-etc.
The only drawback is that it also generates one unnecessary triangle on every pair of rows (on the picture: triangles 4-8-12 and 5-9-13).

In the OP's case, it was not so much of a problem: since his plane was flat, there would only be a few artifacts on the very edge of the grid. However, I want to draw a torus (how are planes and tori related: when you "unfold" a torus, you get a flat surface divided in quadrilaterals). Where the OP in the previous question would only have a few artifacts on some edges, I would have full triangles crossing the surface of the torus. :(

I tried to think of other solutions like this one, which is very similar:

But with this one, instead, triangles 7-4-12 and 10-5-13 are drawn twice.

The easiest, fail-proof solution that I know will work is the one where triangles are stripped separately from every row:

However, I am afraid of performance issues, and it would be unfunny to go with such a solution.

Instead, is there a way to strip all the triangles from the plane in one go, and without unnecessary or double triangles?
Thank you for your time!

  • 5
    "However, I am afraid of performance issues" - this is premature optimization. Implement whatever works and move on. Right now you have stalled your project progress, which is a bigger "performance" issue compared to little gain you might get from optimizing several triangles out. – Kromster says support Monica Mar 28 '17 at 4:58
  • "...and it would be unfunny to go with such a solution." :) But okay, note taken! Thank you for your help, I'll do the last solution first. Out of interest, do you know an answer to my actual question? – qreon Mar 28 '17 at 11:51
4

OpenGL has Primitive Restart functionality for drawing multiple triangle strips. The idea behind this extension is to use a special index value to indicate that a new strip is to be started after that index.

0

Hope that it still can be useful to someone.

//Calculating Vertices
    for (unsigned int z = 0; z < m_size; z++)
    {
        for (unsigned int x = 0; x <= m_size; x++)
        {
            Vertices.push_back(m_startingPos.x + x * m_sqrWidth);       
            Vertices.push_back(m_startingPos.y);                        
            Vertices.push_back(m_startingPos.z + z * m_sqrWidth);       

            Vertices.push_back(m_startingPos.x + x * m_sqrWidth);       
            Vertices.push_back(m_startingPos.y);                        
            Vertices.push_back(m_startingPos.z + (z + 1) * m_sqrWidth); 
        }
    }

    //Calculating Indices
    for (unsigned int z = 0; z < m_size; z++)
    {
        for (unsigned int x = 0; x < m_size; x++)
        {
            unsigned int base = x * 2 + z * (m_size + 1) * 2;
            // bottom-left triangle
            indices.push_back(base + 2); // BR
            indices.push_back(base + 1); // TL
            indices.push_back(base + 0); // BL
            // top-right triangle
            indices.push_back(base + 2); // BR
            indices.push_back(base + 3); // TR
            indices.push_back(base + 1); // TL
        }
    }

m_startingPos is top left corner. m_size is how many squers are in a row/column, m_sqrWidth is a length of cells edge.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.