Jump to content
  • Advertisement
Sign in to follow this  
VanKurt

OpenGL DrawPolygon - How to?

This topic is 4872 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

Hi there! Since I migrated from OpenGL to DirectX I have difficulties even with the simplest things ;-) I guess the solution must be pretty simple, but I don't get it... For drawing a n-Gon in OpenGL the following simple function was all I needed (pseudo-code):
DrawPolygon( CVector2 *verts, uint count )
{
   // Draw all lines except last one
   for( i=0 to count-1 )
   {
      glBegin(GL_LINES);
      glVertex2f( verts, verts[i+1] );
      glEnd();
   }

   // Draw last line
   glBegin(GL_LINES);
   glVertex2f( verts[count-1], verts[0] );
   glEnd();

}

But in DX I have to create a vertex buffer of a fixed size, before I can draw anything. But what if I don't know how many vertices the polygon will have? Is there a flexible way (similar to OGL) to draw such stuff??? Thanks a lot! :-D

Share this post


Link to post
Share on other sites
Advertisement
This is probably the hardest thing to port from GL to DX as it represents a fundamentally different way of providing data to the driver. Anyway, I usually use something like a Vertex Cache to batch up polygons (or lines in your case) for faster rendering. Obviously the more you can batch together the better for performance.

Alan

Share this post


Link to post
Share on other sites
On the MSDN, search for Vertex Buffers (IDirect3DVertexBuffer8), IDirect3DDevice8::DrawPrimitive, and D3DPT_LINELIST.
If you are using D3D9, change the 8 to a 9.
NOTE: You will only need the number of vertices when you draw it, unless you are doing something fancy.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!