# OpenGL newbie question: drawing polys

This topic is 4452 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm just starting out with DirectX 9 programming, (comming from OpenGL) and I've been looking at the ID3DXMesh and the IDirect3DDevice9. It seems both assume that faces are always triangles. I'm probably missing something basic but, is there a way to draw general n-sided polygons in DX?

##### Share on other sites
no. outside of shader programs (which i don't really know anything about), graphics cards can only draw triangles. any n-sided polygon can be decomposed into triangles. but, all modeling programs will make everything into triangles for you so generally there's no need to decompose n-polygons

-me

##### Share on other sites
Ok, I remember in immediate mode in OGL, you could do something like

glBegin(GL_POLY);   // call gl vertex for each poly vertex   glVertex...   glEnd();

and have it do the triangulation for you. I guess there's no equivalent in DX?

##### Share on other sites
As Palidine said, Direct3D solely relies on triangle primitives for drawing 3D shapes. I've dug up a little function I wrote for an ancient model format to triangulate an indexed polygon to a list of triangles. It's no rocket science, but it might be useful:

public static int[][] TriangulatePolygon( int[] polyIndices ){                int triangleCount = polyIndices.Length - 2;    int[][] triangles = new int[triangleCount][];    for(int i = 0; i < triangleCount; i++)    {        triangles = new int[] { polyIndices[0], polyIndices[i + 1], polyIndices[i + 2] };    }    return triangles;}

DirectX doesn't really do immediate mode either, so your best bet is to construct an indexed polygon using vertices and indices (more on that here). You can then fill a vertex & index buffer either with a 'triangle list' obtained from the polygon with the above function or you could tinker with the 'triangle fan' primitive type.

I'd go with the triangle list, since that allows you to stick your polygon in a Mesh object later on, which makes live much simpler. Well, hope this babbling helped somewhat at least :)

##### Share on other sites
ok, cool, thanks!

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 10
• 9
• 9
• 11
• 11
• ### Forum Statistics

• Total Topics
633682
• Total Posts
3013309
×