Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

DirectX 9 - Draw Simple 2D Polygon / Shape

199 views
Skip to first unread message

Kenneth Everett

unread,
May 9, 2003, 1:12:20 AM5/9/03
to
I'm delving into DirectX for the first time, so bear with me. I want to use
C# to draw a variety of 2D polygonal shapes. Eventually I want to add
textures and maybe shift into 3D down the road.

Initially I have been looking at the Tutorial code that comes with the
DirectX 9 SDK. In Tutorial #2 it illustrates what seems like a rather
simple process of defining three vertices to paint a triangle. So, to
extend this to a rectangle, then pentagon, the hexagon, etc., I figured I
could just add a forth vertex array element. This did not work. Am I
missing something simple, or is this tutorial not a good starting point for
drawing 2D shapes with DirectX 9?

Any help, redirection to source material, etc. would be greatly appreciated.

Ken


Lucvdv

unread,
May 9, 2003, 10:45:18 AM5/9/03
to
On Fri, 9 May 2003 00:12:20 -0500, "Kenneth Everett"
<Kenneth...@comcast.net> wrote:

> Initially I have been looking at the Tutorial code that comes with the
> DirectX 9 SDK. In Tutorial #2 it illustrates what seems like a rather
> simple process of defining three vertices to paint a triangle. So, to
> extend this to a rectangle, then pentagon, the hexagon, etc., I figured I
> could just add a forth vertex array element. This did not work. Am I

Look up the difference between "Triangle Lists", "Triangle Fans" and
"Triangle Strips" in online help.

One of them does what you expected, but sample 2 uses another.

> missing something simple, or is this tutorial not a good starting point for
> drawing 2D shapes with DirectX 9?

The tutorials are a perfect place to start.

Tom Miller [MS]

unread,
May 9, 2003, 8:54:36 PM5/9/03
to
It's quite simple to draw 2d polygons. Start with Tutorial 6 (meshes), and
instead of using the Mesh.FromFile method, use the Mesh.Polygon method. For
example:
Mesh polyMesh = Mesh.Polygon(device, 1.0f, 5);

will create a pentagon with a length of 1.. switch 5 to 8, and you have an
octagon..

If you just want the outline of the polygon, you could also do this 'by
hand' like you mention below by using the primitive type LineStrip
instead...

--
- Tom Miller, Dev Lead, Managed DirectX
This posting is provided "AS IS" with no warranties, and confers no rights.


"Kenneth Everett" <Kenneth...@comcast.net> wrote in message
news:#6qWGleF...@tk2msftngp13.phx.gbl...

0 new messages