how to draw concave polygon in jit.gl.sketch ?
Hi list,
I need to draw concave polygon in jit.gl.sketch.
is there a way to do it ?...
please open patch below to see what I mean...
thanks in advance..
Mathieu
________________
Mathieu Chamagne
mathieu.chamagne@free.fr
have the same problem here. found out, that we have to do tessellation. found exhamles, written in c, but i have no idea how to do it in jitter :-(
any gl nerds out there, who can help us ?
drawing a filled polygon with jit.gl.sketch and put a texture on it.
thanx in advance !!
Quoting from the redbook:
"OpenGL polygons must be convex, meaning that they cannot have indentations.
Stated precisely, a region is convex if, given any two points in the
interior, the line segment joining them is also in the interior."
Guess you have to use triangles or triangle_strip for your primitive?
pelado
On Thu, Nov 6, 2008 at 4:09 PM, Mathieu Chamagne
> wrote:
> Hi list,
>
> I need to draw concave polygon in jit.gl.sketch.
> is there a way to do it ?...
Mathieu, I suppose the answer lies in how you intend to use the shape after
it is drawn. There can be many ways to draw a surface, using triangles,
tri_fan, quads etc. Some things to remember:
a) the order that the vertices are drawn is important; b) solid shapes have
two sides;
c) if you draw vertices in a counter clockwise direction then the surface is
'front facing';
d) if you want to draw a non-convex polygon, then you have to break the
surface down into convex polygons, eg triangles;
e) if you want to draw the outline of your surface (poly_mode lines) then
you might get the outline of a triangle that you don't want seen, in which
case you have to use gledgeflags to tell openGL which lines to draw.
Below are some quick examples that might help show some of the differences
and get you on your way:
pelado
thanks very much, Pelado !
your example helped me understand the problem...
I must admit that I didn't took the time to read carefully all the red
book, so I miss some basic opengl concepts...
but my problem is not solved at all, and the solution seems much
complicated than I imagined !
first, let me explain more precisely what 'm trying to do :
I want to be able to draw freely a shape on screen (with mouse, for
ex) ; when mouse button is released, a close shape is created, joining
all the points the cursor passed by.
so :
- I can get a non predictable number of points (between 3 and...)
- if the shape is convex, the polygon method is fine
but, the shape can be ..anything, so...
I want to be able to draw closed and filled shapes (and eventually be
able to apply it a texture afterward...)
example patch :
________________
Mathieu Chamagne
mathieu.chamagne@gmail.com
http://mathieuchamagne.com
http://www.maxobjects.com
Hi!
I thought that the standard way to deal with this was to use a GLU
tesselator (a la red book chapter 11) however, it apparently is not
supported by jit.gl.sketch (based on a brief reading of the help
patcher).. People who know more, please correct me.. I didn't look
much at the patches attached, but assume they're replicating this
functionality in the patch.
I also wondered if maybe jit.gl.lua had wrappers for GLU/GLUT but
couldn't determine that quickly..
Best,
David
Mathieu Chamagne wrote:
> thanks very much, Pelado !
>
> your example helped me understand the problem...
> I must admit that I didn't took the time to read carefully all the red
> book, so I miss some basic opengl concepts...
>
> but my problem is not solved at all, and the solution seems much
> complicated than I imagined !
>
> first, let me explain more precisely what 'm trying to do :
> I want to be able to draw freely a shape on screen (with mouse, for ex)
> ; when mouse button is released, a close shape is created, joining all
> the points the cursor passed by.
> so :
> - I can get a non predictable number of points (between 3 and...)
> - if the shape is convex, the polygon method is fine
> but, the shape can be ..anything, so...
>
> I want to be able to draw closed and filled shapes (and eventually be
> able to apply it a texture afterward...)
>
> example patch :
..snip..
>
>
>
> ________________
> Mathieu Chamagne
> mathieu.chamagne@gmail.com
> http://mathieuchamagne.com
> http://www.maxobjects.com
>
>
>
>
Mathieu, I don't know the answer to your problem, sorry. One thing that
crosses my mind is that as a user draws a shape in the window, they are not
really describing a 'surface', instead they are defining the outline of a
surface that gets filled according to the openGL rules for the primitive
used. So, if I draw a doughnut with polygons the outline would describe the
doughnut but the surface would appear more like a circle (a 2d shape viewed
from the screen). Therefore, to accurately fill-in a surface described by
your user, I would think you would need to have the outline described first
and then to fill it in afterwards?
David, as far as I'm aware you are correct that jit.gl.sketch doesn't
support tesselation, which would help Mathieu with a solution. I don't know
about jit.gl.lua.
pelado
On Fri, Nov 7, 2008 at 2:54 PM, Mathieu Chamagne
> wrote:
> thanks very much, Pelado !
>
> your example helped me understand the problem...
> I must admit that I didn't took the time to read carefully all the red
> book, so I miss some basic opengl concepts...
>
> but my problem is not solved at all, and the solution seems much
> complicated than I imagined !
>
> first, let me explain more precisely what 'm trying to do :
> I want to be able to draw freely a shape on screen (with mouse, for ex) ;
> when mouse button is released, a close shape is created, joining all the
> points the cursor passed by.
> so :
> - I can get a non predictable number of points (between 3 and...)
> - if the shape is convex, the polygon method is fine
> but, the shape can be ..anything, so...
>
> I want to be able to draw closed and filled shapes (and eventually be able
> to apply it a texture afterward...)
>
thanks again Pelado,
yes, I arrived to the same conclusion ; so the problem is now : how to
fill a shape described by points ? (in opengl...)
maybe I will try drawing in a matrix instead of opengl, and then
something like "close the blob" to fill the shape, and send it to a
texture to display it...
it will probably look worse than pure opengl drawing !
.. I didn't imagine that such a simple task would become so
complicated !
I will think about it this week end...
thanks for your help.
Mathieu
________________
Mathieu Chamagne
mathieu.chamagne@gmail.com
http://mathieuchamagne.com
http://www.maxobjects.com
anyone from cycling here to help ?
it would be great if we could draw a concave
polygon in opengl !
my suggestion is: defining a new draw type "polygon_filled",
which works similar to the line_loop.
or: give us an interface to tesselation in jit.gl.sketch !
thanx in advance :-)
that's not going to happen. the primitives are defined by the openGL
spec, not by cycling. why not use tri_grid? you can make all of the
dented polygons you want with that.
On Nov 8, 2008, at 6:35 AM, videomasta wrote:
>
> anyone from cycling here to help ?
>
> it would be great if we could draw a concave
> polygon in opengl !
>
> my suggestion is: defining a new draw type "polygon_filled",
> which works similar to the line_loop.
>
> or: give us an interface to tesselation in jit.gl.sketch !
>
> thanx in advance :-)
ah. thinking about this, you want this for 2 dimensional filled shapes.
what about using multiple rows of polygon vertex groups as primitives
to make more complex shapes?
On Nov 8, 2008, at 7:46 AM, joshua goldberg wrote:
> that's not going to happen. the primitives are defined by the
> openGL spec, not by cycling. why not use tri_grid? you can make
> all of the dented polygons you want with that.
>
> On Nov 8, 2008, at 6:35 AM, videomasta wrote:
>
>>
>> anyone from cycling here to help ?
>>
>> it would be great if we could draw a concave
>> polygon in opengl !
>>
>> my suggestion is: defining a new draw type "polygon_filled",
>> which works similar to the line_loop.
>>
>> or: give us an interface to tesselation in jit.gl.sketch !
>>
>> thanx in advance :-)
>
thanks a lot for your fast reply joshua :-)
but i did not get it how i can make "multiple rows of polygon vertex groups"
and fill it afterwards with one texture (in my case a movie)
it would be great, if you can post a smal patch
for explanation :-)
all the best !
ah. thinking about this, you want this for 2 dimensional filled shapes.
what about using multiple rows of polygon vertex groups as primitives
to make more complex shapes?
sorry, I've no idea on how to use "multiple rows of polygon vertex
groups as primitives"...
would you give us an example, please ?
thanks in advance
Mathieu
________________
Mathieu Chamagne
mathieu.chamagne@gmail.com
http://mathieuchamagne.com
http://www.maxobjects.com
not necessarily in the same thread,
if you're going to do low rent (non-GLU) tesselation, here is a
candidate algorithm, ear cutting:
http://cgm.cs.mcgill.ca/~godfried/teaching/cg-projects/97/Ian/cutting_ears.html
however, it will involve work to implement in max. i'm surprised that
the GLU teselator isn't hooked in the jit.gl.sketch and that nobody has
seen fit to even create an external binder for it. given the general
completeness of the jitter implementations of things, and how this can't
be an uncommon problem, this is surprising. maybe this is a different
use-case than the typical/preferred jitter ones?
it also seems like putting the geometry into a matrix and then
converting using jit.gl.mesh could be a (less elegant?) solution if
you're looking for hackery..
*trying* (but probably not succeeding) to be useful,
david
Mathieu Chamagne wrote:
> sorry, I've no idea on how to use "multiple rows of polygon vertex
> groups as primitives"...
> would you give us an example, please ?
>
> thanks in advance
>
> Mathieu
> ________________
> Mathieu Chamagne
> mathieu.chamagne@gmail.com
> http://mathieuchamagne.com
> http://www.maxobjects.com
>
>
>
>
>
hi all,
i did a workaround for drawing filled concave polygons in 2d space.
it is impossible with the polygon primitive of opengl.
you have to split the shape into triangles.
the attached example includes a javascript, which is a port from the
algortithm from John W. Ratcliff [jratcliff@verant.com]
http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml
the original code is programed in c++. perhaps someone can glue
an external out of it.
it triangulates simple polygons/conturs
(without holes, without overlapping contour)
this javascript solution is deadslow in contrast to
the opengl GLU teselator.
to cycling: it would be great, if could implement the GLU teselator !!!
it is a very important feature of opengl.
hope this quickhack helps a bit :-)
sincerely your videomasta
great !
thanks, that's exacty what I was looking for !
> it triangulates simple polygons/conturs
> (without holes, without overlapping contour)
>
> this javascript solution is deadslow in contrast to
> the opengl GLU teselator.
right, it's very sloooowwww...
but in my case, not really a problem.
remains the holes & overlapping contour cases...
but that's better than nothing !
thanks very much
bests
MAthieU
________________
Mathieu Chamagne
mathieu.chamagne@gmail.com
http://mathieuchamagne.com
http://www.maxobjects.com