Understanding EPT_TRIANGLE_STRIP

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
mazataza
Posts: 17
Joined: Wed Jan 16, 2013 7:36 am
Location: Karlsruhe, Germany

Understanding EPT_TRIANGLE_STRIP

Post by mazataza »

I miss something here .
I have the following polygon:
v0, v1, v2, v3 ( you can see it as line loop here and counter clock wice)
now if i want to convert this polygon to traingle (in a simple way and using EPT_TRIANGLES) it will be
T1: v0,v1,v2
T2: v0,v2, v3

but when i want to use EPT_TRIANGLE_STRIP i should build the vertex for the buffer like
v0,v1,v2,v3,v0
so it will create following traingles
T1: v0,v1,v2
T2: v1,v2,v3
T3: v2,v3,v0

which means to draw a polygon as a traingle i need 3 Traingles with 5 vertex when using EPT_TRIANGLE_STRIP and I need 2 Traingles with 6 vertex when using EPT_TRIANGLES.
I see the different only on memory usage for the vertex buffers. but what about the speed in the opengl engine?
The whole thing it depend on how i put the vertex in the buffer. in the above buffer if i want to draw the polygon with two Traingle and 4 vertex i should declare the vertex like
v2,v0,v1,v3
this will generate t
T1: v2,v0,v1,
T2: v0,v1,v3

is my assumption here are correct?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Understanding EPT_TRIANGLE_STRIP

Post by hybrid »

No, you don't need more vertices or indices. Simply use 1,2,3,0 as indices, which will render also two triangles as a quad. The thing is that for tri_strip, the last line is always repeated in reverse order as start, and then the next index is used as third point. You have to check if this fits your purposes.
mazataza
Posts: 17
Joined: Wed Jan 16, 2013 7:36 am
Location: Karlsruhe, Germany

Re: Understanding EPT_TRIANGLE_STRIP

Post by mazataza »

can you describe how to call drawVertexPrimitiveList to draw the quad as you describe the indices?

Actually i don't want to draw only a quad. my user may create a polygon with more than 4 edges and can be convergence or not, thus i will use an algorithm which then generate a traingles from the polygon.
then i will draw them with drawVertexPrimitiveList.

my issue will be on how got from the generated traingles the correct vertex order :D
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Understanding EPT_TRIANGLE_STRIP

Post by hybrid »

You can probably save a lot more render cycles by using standard layout hardware vertex buffers. Though we have a patch already for support of hardware buffers for generic render lists, it's much simpler and still quite efficient to do so with simple triangles.
Anyway, the call is drawVertexPrimitiveList(vertices, 4, indices, 2, EPT_TRIANGLE_STRIP) with vertices an array of S3DVertex as above (0,1,2,3) and indices an array with just integers [1,2,3, 0]. Indices can also be [0,1,2,3] as I just found out, not sure why I first thought that you have to use a different order. It's just a different edge to continue with, and the diagonal intersection is differently oriented.
mazataza
Posts: 17
Joined: Wed Jan 16, 2013 7:36 am
Location: Karlsruhe, Germany

Re: Understanding EPT_TRIANGLE_STRIP

Post by mazataza »

I will try it today late.
but i can remember i done like you said but i got such a surface

|.................|
|...|..........|.|
|......|....|....|
|.........|......|
|____________|

intepretate "...." as empty spaces.
As you say it didnt draw the quad correctly.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Understanding EPT_TRIANGLE_STRIP

Post by hybrid »

Well, this text figure is not really conclusive, but here's what it should look like for the first case

Code: Select all

 
1       2
--------
|\      |
|  \    |
|   \   |
|    \  |
|      \|
--------
0        3
 
and the second

Code: Select all

 
1       2
--------
|      /|
|    /  |
|  /    |
|/      |
--------
0        3
 
mazataza
Posts: 17
Joined: Wed Jan 16, 2013 7:36 am
Location: Karlsruhe, Germany

Re: Understanding EPT_TRIANGLE_STRIP

Post by mazataza »

here is my code i am using to initialize the buffer

Code: Select all

 
m_buffer = new irr::scene::CDynamicMeshBuffer(irr::video::EVT_STANDARD, irr::video::EIT_16BIT);
    m_buffer->getMaterial().Wireframe = false;
    m_buffer->getMaterial().Lighting = false;
    m_buffer->getMaterial().Thickness = 1;
    m_buffer->getMaterial().FogEnable = false;
    m_buffer->getMaterial().ZWriteEnable = false;
    m_buffer->getMaterial().BackfaceCulling = false;
    m_buffer->getMaterial().AntiAliasing = true;
 
    // Set the default culling state to Frustum Box
    AutomaticCullingState = scene::EAC_FRUSTUM_BOX;
    u32 indexIndex = 0;
    m_buffer->getVertexBuffer().push_back(video::S3DVertex(vec[0], core::vector3df(0,1,0), m_backlgcolor, core::vector2df(0.0f, 0.0f)));
    m_buffer->getIndexBuffer().push_back(indexIndex++);
    m_buffer->getVertexBuffer().push_back(video::S3DVertex(vec[1], core::vector3df(0,1,0), m_backlgcolor, core::vector2df(0.0f, 0.0f)));
    m_buffer->getIndexBuffer().push_back(indexIndex++);
    m_buffer->getVertexBuffer().push_back(video::S3DVertex(vec[2], core::vector3df(0,1,0), m_backlgcolor, core::vector2df(0.0f, 0.0f)));
    m_buffer->getIndexBuffer().push_back(indexIndex++);
    m_buffer->getVertexBuffer().push_back(video::S3DVertex(vec[3], core::vector3df(0,1,0), m_backlgcolor, core::vector2df(0.0f, 0.0f)));
    m_buffer->getIndexBuffer().push_back(indexIndex++);
....
driver->setMaterial(m_buffer->getMaterial());
        driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
 
        driver->drawVertexPrimitiveList(m_buffer->getVertexBuffer().getData(),  // const void* vertices
            m_buffer->getVertexBuffer().size(),             //u32 vertexCount
            m_buffer->getIndexBuffer().getData(),   // const void* indexList
            m_buffer->getVertexBuffer().size()-2,   // u32 primCount
            m_buffer->getVertexType(),                              // E_VERTEX_TYPE vType
            scene::EPT_TRIANGLE_STRIP,                                               // scene::E_PRIMITIVE_TYPE pType
            m_buffer->getIndexType() );                             // E_INDEX_TYPE iType
    
 
the out put is

Code: Select all

 
1            2
------------
|           |
|           |
|    /\    |
|  /    \  |
|/       \ |
0           3
 
sorry i can't get the text figure correctly but you see there is a part from the quad is not build.
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: Understanding EPT_TRIANGLE_STRIP

Post by serengeor »

Clearly indices for vertices 1, 2 are the ones "repeated" while it should be the 1, 3 or 0, 2.

Your indices are 0,1,2,3 as far as I can tell from that code. They should probably go like 0, 1, 3, 2
Working on game: Marrbles (Currently stopped).
mazataza
Posts: 17
Joined: Wed Jan 16, 2013 7:36 am
Location: Karlsruhe, Germany

Re: Understanding EPT_TRIANGLE_STRIP

Post by mazataza »

yes it work with your suggestion.
What i am try to figure is when i generate traingles from a polygon i don't know how to generate the indices. thus i will use the triangles type which i need to define each traingle in the vertex buffer, this is will need more memory but i don't have alot of traingles. for each node it will be max 100 traingles and i will have per max 100s of nodes per frame.
Post Reply