Thread: Drawing circles in DirectX 8

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    87

    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.
    PuterPaul.co.uk - Portfolio site

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    87
    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!!!!
    PuterPaul.co.uk - Portfolio site

  3. #3
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    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++)
    {
    x=cos(degrees*PI/180)*radius;
    y=sin(degrees*PI/180)*radius;
    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
    Away.

  4. #4
    Registered User Coder's Avatar
    Join Date
    Aug 2001
    Location
    Cairo, Egypt
    Posts
    128
    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

    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 ).
    Muhammad Haggag

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. DirectX | Drawing text
    By gavra in forum Game Programming
    Replies: 4
    Last Post: 06-08-2009, 12:23 AM
  2. DirectX | Simple Drawing
    By gavra in forum Game Programming
    Replies: 8
    Last Post: 05-31-2009, 05:17 PM
  3. Drawing JPEGs (DirectX?)
    By Flaug in forum C++ Programming
    Replies: 2
    Last Post: 05-21-2009, 05:15 PM
  4. DirectSound header issues
    By dxfoo in forum C++ Programming
    Replies: 0
    Last Post: 03-19-2006, 07:16 PM
  5. Drawing circles
    By chomper in forum Windows Programming
    Replies: 3
    Last Post: 05-07-2002, 12:37 PM