Results 1 to 6 of 6

Thread: Simple polygon drawing

  1. #1

    Red face Simple polygon drawing

    I'm completely new to clanlib, but i've seen it in action while participating to projects that involved this library.

    I've probably got a really stupid question, but i keep googling for it and looking in the doc, I can't find an answer...
    My question is :
    Is there a proper way to draw a 2d polygon (pentagon, octagon for example, or a completely custom shape) and to apply a texture to it?

    The second part of the question should not be that tricky when the first one is correctly done, but the only way I managed to draw a custom shape is to draw it line by line, with "CL_Draw::line". Hence i can't fill it...

    Any suggestions?

    Thanks in advance for helping.

  2. #2


    Ok, after some research, I finally found an answer, and I succeeded to make it work.

    Howto (brief ) :

    For drawing a complex polygon with Clanlib, you have to cut it into triangles, an then to draw each triangle individually.
    Thanks to the triangulator classes (see doc), the process is actually quite easy.

  3. #3

    Default Concave polygon triangulation

    I am in a similar situation to gwenp -- but in my case the delauney triangulator doesn't help, because it gets confused with concave polygons and I haven't been able to get the Ear-clipping triangulator to work, the class keeps returning an unitialized vector of triangles. This with ClanLib-2.3.6.
    Any hints?

    BTW; the is the triangulator stuff considered WIP? I am surprised that the different implementations do not have a common interface and that they return arrays that need further work to be used e.g. with CL_GraphicContext.draw_primitives().

  4. #4
    Master Sorcerer
    Join Date
    Sep 2006


    Do not use the delauney triangulators - they are broken (as you noticed yourself) and should be removed (no active maintainer on them).

    The ear-clip triangular should be working though. Do you have an example that breaks it?

  5. #5


    Quote Originally Posted by Magnus Norddahl View Post
    The ear-clip triangular should be working though. Do you have an example that breaks it?
    I found a way to solve the issue.
    This segfaults (the impl pointer gets deleted):

    CL_EarClipResult result = triangulator.triangulate().get_triangles();
    This doesn't:
    CL_EarClipResult result = triangulator.triangulate();
    std::vector<CL_EarClipTriangulator_Triangle> & triangles = result.get_triangles();
    It still seems to miss 1 triangle sometimes, depending on the data. I haven't been able to isolate what causes it. This is my current code, in case you are interested:
    Thank you for your help.

  6. #6


    In the GLU library there are functions for tesselation.
    I think that you can use it even if you don't use OpenGL (at least not directly).
    Maybe you can use it directly, but in case not (if you do 2D) I think you can still take its souces because I think that it's FLOSS software.

    You may also use the GLU tesselation functions in your main program or, you can also tesselate your data before running your program, and then save and use the data that are already tesselated.
    Last edited by luwak; 11-06-2012 at 08:34 AM. Reason: pre-proc

Similar Threads

  1. how to make a simple app
    By singhking in forum Game development
    Replies: 11
    Last Post: 02-07-2013, 11:55 PM
  2. Simple Full Screen Example
    By rombust in forum Official ClanLib SDK Forums
    Replies: 0
    Last Post: 08-15-2011, 11:49 AM
  3. Simple Map Import
    By Uhfgood in forum Novashell Game Creation System
    Replies: 3
    Last Post: 09-30-2009, 04:43 AM
  4. Simple Path Movement
    By Pleng in forum Novashell Game Creation System
    Replies: 11
    Last Post: 03-22-2008, 11:30 AM
  5. Simple Animation
    By ares in forum Official ClanLib SDK Forums
    Replies: 1
    Last Post: 02-27-2008, 05:20 AM



Posting Permissions

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