D3d Drawing 2d objects

Kesper

New member
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 cant 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 its convex, you could use a simple Triangle Fan. Dont 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 cant speak of the performance as Ive never really tried generating objects and loading surfaces per-frame. If youre not worried about the framerate and only need to generate the shapes once to prepare a surface there shouldnt be any problem.

-nerseus
 
Originally posted by Nerseus
You can use GDI to draw onto surfaces fairly easily.

You know what, I never thought it was possible, even if it was before my eyes... :eek:

EDIT: Wrong forum, anyway :P
 
Last edited by a moderator:
Back
Top