# 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.

## 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 on other sites
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 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.

1. 1
Rutin
45
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632987
• Total Posts
3009729
• ### Who's Online (See full list)

There are no registered users currently online

×