# Drawing circles in DirectX 8

• 07-22-2002
pdstatha
Drawing circles in DirectX 8
Umm this is probably a very dumb question, but how do you draw a circle??

I know how to draw things like triangles and rectangles, but I haven't come across a circle as of yet.
• 07-22-2002
pdstatha
I'm not really too sure how to go about this, basically I'm trying to program a breakout clone. I've already made a series of bitmaps for the game to use, i.e. the blocks, paddle and the ball.

Reading around I have come to the impression that even though this is a 2d game that I have to use vertices and matrices.

I had originally thought that what happened was bitmaps were loaded into the game and used as the objects, but it seems that the shapes are created and then the bitmaps are textured onto them!!!!

Also is there some sort of layering system, as in photoshop i.e. where the background of the D3D app can be set and then layers of objects can be put on top???

Someone please give me a good explanation cos I am mega confused right now!!!!
• 07-22-2002
confuted
well, I don't know directx, so there might be a function to draw a circle, but here is another way...using putpixel.

for (degrees=0;degrees<360;degrees++)
{
putpixel(x,y);
}

multiplying degrees by PI/180 converts it to radians, which is what all the trig functions in C use. Radius is the radius of your circle, obviously, and I just used a psuedo putpixel (: You can obviously optimize that a little bit...but that is probably good enough for a 2D game
• 07-27-2002
Coder
Quote:

I had originally thought that what happened was bitmaps were loaded into the game and used as the objects, but it seems that the shapes are created and then the bitmaps are textured onto them!!!!
Assuming you're using something like ID3DXSprite, this is what happens : You define a primitive ( a rectangle, consisting of 2 triangles ) and then texture your bitmap on it.

To draw a circle, you can :

1 - Use a bitmap
2 - Make a loop like the one blackrat wrote, but instead of plotting pixels, store the x & y values in a vertex array/buffer and then render the array/buffer as a linestrip using DrawPrimitiveUP/DrawPrimitive

Quote:

Also is there some sort of layering system, as in photoshop i.e. where the background of the D3D app can be set and then layers of objects can be put on top???
You can achieve that by :

1 - Rendering ( drawing ) your objects in order : The background first, and then the objects. That'd require you to classify your objects to layers, and then render the layers in order.

2 - Use Z buffer : That means you will have to enable z buffering.
I'm not sure if it works with transformed and lit ( 2D ) vertices ( I think it does, since TL vertices have a z member ), but if it doesn't, you can use untransformed vertices along with orthogonal projection. Orthogonal projection gives you a means to do 2D graphics in DirectGraphics with all the features of 3D graphics ( like doing rotations using matrices ).