Jump to content
  • Advertisement
Sign in to follow this  
indigox3

OpenGL newbie question: drawing polys

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!