Results 1 to 5 of 5

Thread: How to draw a changeable circle in clanlib?

  1. #1

    Default How to draw a changeable circle in clanlib?

    Hi All

    I am trying to draw a circle which will have a 2 portions (like a pie). I want to be able to change the divide between the two portions at runtime.

    E.g Imagine pacman, his head is section one and the gap between his mouth is section 2. I want to be able to increase and decrease the size of the gap.

    Any help would be greatly appreciated. Thanks.

    All the best,
    Martin

  2. #2
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    551

    Default

    ClanLib is not particular strong in vector graphics. So drawing a circle with a gap in it would require triangulating the figure and then draw it with GraphicContext.draw_primitives.

    However this is usually not how it is done in games. Most games simple use a set of images that form the animation desired. This is also how the pacman game does it - there is 5-10 images that show each state the pacman can be in. CL_Sprite in ClanLib was made for doing these kinds of animations.

  3. #3

    Default

    Thanks for the reply.

    That makes sense really. I built a circle using 360 small triangle primitives which looks fine. but when i want to alter the size its really slow. I cant really use a small set of pre-made images because I have to alter the circle size by 1 degree if needed. I am thinking about splitting a circle image into 360 small images and then draw the relevant amount. Ill let you know how it goes. if that is still slow I will have to compromise down to say 5 or 10 degree images.

    All the best,
    Martin

  4. #4
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,787

    Default

    Depending on your situation.

    An alternative is drawing a whole circle.

    Then draw a triangle to cut out the required segment.

    That's simple when drawing to a background with a constant color.

    Else, you have use a framebuffer to draw the circle onto and by disabling blending draw a triangle with CL_Colorf::transparent i.e. alpha=0.0f; Then draw the framebuffer texture to the screen. But that's tricky unless you have had lots of experience with ClanLib API.

    Else, look at ClanLib source at CL_Draw::circle(), copy it into your code and modify it.

    The CL_Draw class only contain helper functions ... and is useful to understand how ClanLib works.

  5. #5

    Default

    Thank you for your reply. I ended up using four quarter CL_images each containing a quarter of the circle. I then only draw triangles for 90 degrees of the circle. once it passes the angle, the relevant quarter is draw and then the triangles are drawn following after the quarter. It works well and because I increment the angle by a greater amount its much faster. Thank you for all your help.

    All the best,
    Martin.

Similar Threads

  1. Bug when I draw a set of sprites
    By butterquark in forum Official ClanLib SDK Forums
    Replies: 10
    Last Post: 10-03-2011, 02:21 PM
  2. CollisionOuline Draw ?
    By Jason Schilling in forum Official ClanLib SDK Forums
    Replies: 1
    Last Post: 08-02-2011, 04:01 PM
  3. CL_Sprite draw problem
    By Aikidos in forum Official ClanLib SDK Forums
    Replies: 1
    Last Post: 04-22-2011, 02:08 PM
  4. draw sprites without background
    By Koli14 in forum Official ClanLib SDK Forums
    Replies: 5
    Last Post: 01-14-2010, 09:26 AM
  5. GDI Target Draw Problems
    By rombust in forum Official ClanLib SDK Forums
    Replies: 1
    Last Post: 05-01-2009, 01:21 PM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •