i read some vertex and polygons from a file. But i don’t know at compile time whether these polygons are triangulated or not. Is there a way to draw mulit edged polygons and use this instead of drawTriangles, or would it better to triangulate the data first and draw after that?

If you’re using the compatibility profile, you can use glDrawElements(GL_POLYGON) to draw a single polygon. I assume that you can use glMultiDrawElements() for multiple polygons. I don’t know whether primitive restarting works with polygons.

But GL_POLYGON only works for convex polygons; the behaviour is undefined for non-convex polygons.

In general, it’s preferable to tessellate polygons into triangles, regardless of convexity. Even if the OpenGL implementation does this itself, the exact behaviour will vary between implementations. Doing it yourself ensures consistent and predictable behaviour.

Non-convex polygons can be drawn as triangle fans, using stencilling to identify the interior. This can be an appropriate solution for very complex polygons if you’re only drawing a few of them (e.g. maps, where region boundaries are often dictated by geographical features such as rivers or coastlines).

I need your help once more with this problem. My triangulation seams not to work.

i have multiple model chunks stored in vModels.
Each Model can have one ore more segments stored in segmLst.
and each Segment has one or more polygons stored in meshIndices
each polygon should have at least 3 vertices
and each vertex has 3 coordinates and 2 uv

for (auto& modIt : vModels) // for every model chunk
{
for (auto& segIt : modIt->segmLst) // for every cluster
{
for (auto& mshIt : segIt->meshIndices) // for every polygon
{
if (mshIt->size() >= 3) // multipoly
{
// for every triangle of the multi polygon
for (unsigned int tri = 0; tri < mshIt->size() - 2; tri++)
{
// for every edge of the triangle
for (int triEdge = 0; triEdge < 3; triEdge++)
{
Vertex tempVertex;
// every edge has 3 coordinates
for (int j = 0; j < 3; j++)
tempVertex.position[j] = (GLfloat)segIt->vertex[(*mshIt)[triEdge > 0 ? tri + triEdge : 0] * 3 + j];
// and 2 UV
if (segIt->uv == NULL)
{
tempVertex.uv[0] = 1.0;
tempVertex.uv[1] = 1.0;
}
else
{
for (int j = 0; j < 2; j++)
tempVertex.uv[j] = (GLfloat)segIt->uv[(*mshIt)[triEdge > 0 ? tri + triEdge : 0] * 2 + j];
}
tempBufferData.push_back(tempVertex);
}
}
}
else // this shouldn't happen (polygon with less then 3 vertex)
{
deleteVectors();
MessageBox(NULL, "You have polygons with less then 3 vertices!", "MeshViewer 2.0 Error", MB_OK | MB_ICONERROR);
return;
}
}
}
}

on the two first pictures you can see the result and my problem. The polygons are not triangulated correctly.

And on the last you can see my idea about triangulation. the n = 6 edged polygon is split into n - 2 = 4 triangles using the edges (0,1,2), (0,2,3), …, (0, n-2, n-1)

[ATTACH=CONFIG]1410[/ATTACH]

So there are two options:

my triangulation idea is stupid.

my code is wrong.

i guess it’s 2) and i hope you can find the problem

Ok, i think i’ll check that code tomorrow, because when i look at my result it feels like i even don’t touch all vertices. So i think i did something wrong there.
About cw/ccw it’s a bit crazy. the file format stores the polygons cw, ccw, cw, ccw, cw, ccw,… Don’t ask me why it isn’t only cw/ccw http://schlechtwetterfront.github.io/ze_filetypes/msh.html#STRP

==EDIT==

i checked it and it looks like a problem of my data. Because my calculation builds the correct triangles 0,1,2 and 0,2,3
But it seams that my data is like that:
23
01

and not
01
23

you see?? the edges are not calculated one after the other

Since triangle strips are deprecated in GL 3.x, and if you don’t want to get stuck with GL 2.x, I still suggest to move to triangles. Since now you know you have triangles strips, so since the third vertex, you add only vertex by vertex to fulfill a full triangle (with reversing its winding each time), then you can easily change your algorithm to create normal triangles.