D3d Drawing 2d objects

Kesper

Newcomer
Joined
Feb 2, 2003
Messages
4
Location
Washington State
I am working on the GUI part of my engine and notice that there are samples on drawing text to the screen in 2d (and even makeing the text 3d) But I can't figure out how to draw simple shapes like rectangles, triangles, circles...etc.

What I would realy like to know is how to use gdi+ to create a shape and d3d9 to draw it to the screen. Anyone know how this is done? I am useing VB.net and DX9.

Kesper
 
You can use GDI to draw onto surfaces fairly easily.
For example (taken from the DX9 wizard generated code, mostly):
C#:
Bitmap bmp = new Bitmap(1, 1, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp);
// Do your drawing on g ...

Texture texture = Texture.FromBitmap(device, bmp, 0, Pool.Managed);

Most non-circular shapes can be drawn in Direct3D by breaking your shape into triangles. Obviously, squares and rectangles are the easiest (next to triangles :)). A hexagon or a more "random" object might be slightly harder. If it's convex, you could use a simple Triangle Fan. Don't forget Direct3D can draw lines as well - just use LineList instead of TriangleList.

For circles, arcs, bezier curves and such you might actually do well to use GDI. I can't speak of the performance as I've never really tried generating objects and loading surfaces per-frame. If you're not worried about the framerate and only need to generate the shapes once to prepare a surface there shouldn't be any problem.

-nerseus
 
Back
Top