Results 1 to 5 of 5

Thread: Add extra methods for drawing primitives

  1. #1

    Default Add extra methods for drawing primitives

    I'd like to see some extra methods on the canvas for drawing solid/dashed circle outlines and arc and such. I've been doing a few things myself and have an implementation for drawing arcs written
    void draw_arc(clan::Canvas & canvas, const clan::Pointf & center, const float radius, const float start_angle, const float arc_angle, const int num_segments,const clan::Colorf & color = clan::Colorf::white)
    	float theta = arc_angle / float(num_segments - 1);
    	float tangetial_factor = tanf(theta);
    	float radial_factor = cosf(theta);
    	float x = radius * cosf(start_angle);
    	float y = radius * sinf(start_angle);
    	std::vector<clan::Vec2f> points(num_segments);
    	for(int i = 0; i < num_segments; i++)
    		points[i] = clan::Vec2f(x+center.x,y+center.y);
    		float tx = -y; 
    		float ty = x;
    		x += tx * tangetial_factor; 
    		y += ty * tangetial_factor; 
    		x *= radial_factor; 
    		y *= radial_factor; 

  2. #2
    ClanLib Developer
    Join Date
    May 2007


    I'm unsure if that function would be better on the clan::Shape2D class.

    If your function was on the clan::Shape2D class, it would work as an outline and filled. It could be also cached by the application code (i.e. only recreate the outlines/triangles when required).

    On a side note, adding it as a draw_arc(), fill_src() to the clan::Canvas :

    The other week, I replied to pap, who had the following suggestion to add a function to clan::Canvas:
    void draw_circle(clan::Canvas &canvas,const clan::Pointf center,const float radius,const clan::Colorf color) {
      // A workaround for the lack of canvas.draw_circle() method.
      clan::Shape2D shape;
      std::vector<clan::Vec2f> circle;
    My reply was:

    "I thought about that myself. But decided against it. Although draw_circle() is a nice convenience function, it is relatively slow. Also, I am not sure it's useful.
    I also thought of adding Shape2D::draw_circle() static. But the code to do it is so trivial, it would just add to ClanLib API bloat.
    I am now unsure.

  3. #3


    Great. That's awesome to hear.

    I experimented with that particular code however found it quite slow (comparatively) to the code I posted especially as the circle radius was increased past a threshold.

    As glLineStipple has now been depreciated looking at other means for fast and customisable line drawing. It seems like geometry shaders is the way to go but that requires adjacency primitives to proceed.

  4. #4
    ClanLib Developer
    Join Date
    May 2007


    Maybe you can use a texture containing the line.

    For example the texture contains various line stippling combinations:

    ######## <--- Solid line

    And use " void draw_lines(const Vec2f *line_positions, const Vec2f *texture_positions, int num_vertices, const Texture2D &texture, const Colorf &line_color = Colorf::white);"
    (With Texture2D set to repeat)

    By adjusting the x2 coordinate of the texture position, controls the stippling size

    You can need to disable Texture2D linear filtering as well

  5. #5


    Thanks for that idea, it seems to work great in certain use cases. It tends to fall flat when I want to adjust the line width. glLineWidth also appears to be depreciated in opengl 3.0+ Ideally these lines would be a fixed width regardless of the cameras position. I've experimented with generating the geometry (for lines) on the cpu but to get that i would have to regenerate the entire buffer each frame.

Similar Threads

  1. Scammer methods
    By DHK123 in forum Bugs & Glitches
    Replies: 1
    Last Post: 09-20-2013, 07:13 PM
  2. Replies: 3
    Last Post: 03-13-2012, 02:50 AM
  3. Templated datatype primitives in ClanLib 0.9
    By rombust in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 01-29-2009, 11:29 AM
  4. Drawing primitives in ClanLib 0.8
    By LonelyStar in forum Official ClanLib SDK Forums
    Replies: 1
    Last Post: 05-12-2008, 09:36 PM



Posting Permissions

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