Slick Forums
http://slick.ninjacave.com/forum/

BUG: Filling a curved closed shape problems
http://slick.ninjacave.com/forum/viewtopic.php?f=1&t=5870
Page 1 of 1

Author:  LosTChG [ Tue Nov 20, 2012 12:35 am ]
Post subject:  BUG: Filling a curved closed shape problems

Hello!

I've just finished porting a project from Java2D and, surprisingly, everything appears to work fine. The FPS have raised a lot since I use Slick2D, so thanks for giving birth/maintaining this library :D

However, I have found that when I g.fill a closed shape made of cubic curves, the filling always lacks of one triangle (the one between the last control point of the last curve and random points from the first curve), as you can see clearly in this image:

Image

Does someone else have this problem? How could I solve this?

Looking forward to your responses, and thanks for all!

Author:  davedes [ Wed Nov 21, 2012 6:09 pm ]
Post subject:  Re: BUG: Filling a curved closed shape problems

It seems to be a bug with Slick's triangulator. I don't know enough about triangulation to try and debug it, unfortunately.

The suggestion I made in another thread was to use Java2D for primitive rendering. The fixed OpenGL pipeline is not ideal for 2D primitive rendering, anyways: some drivers don't support anti-aliasing of 2D shapes, some drivers use different pixel offsets, some drivers have limited line width support, etc. Since Java2D is a software renderer, these problems don't exist with it.

You can see an example of how to efficiently upload Java2D primitive shapes to Slick here:
viewtopic.php?p=31326#p31326

Author:  LosTChG [ Wed Nov 21, 2012 7:51 pm ]
Post subject:  Re: BUG: Filling a curved closed shape problems

Heh, davedes, you are everywhere, amazing!
Thanks for the info! I have just also visited one of my post you replied half a month in libgdx forums regarding primitive rendering too, and I should have read it earlier, because It would have saved me all the porting process to slick2d >_<
Baaack to libgdx :P

Author:  LosTChG [ Fri Jan 04, 2013 1:18 am ]
Post subject:  Re: BUG: Filling a curved closed shape problems

It would be very difficult to implement poly2tri triangulator in Slick? It would solve all my problems :D

Author:  davedes [ Sat Jan 05, 2013 1:19 am ]
Post subject:  Re: BUG: Filling a curved closed shape problems

Nope, but it would probably be easier to just use LibGDX.


In Slick it would look like this: (pseudo code)
Code:
//make polygon, array of Points or Vector2 or whatever
input;

//poly2tri has its own polygon class
p = new Poly2TriPolygon(input);

//Poly2Tri should have some static methods to triangulate a polygon
List<Triangle> tris = Poly2Tri.triangulate(p);

//draw outline
glBegin(GL_LINES);
for each triangle:
    glVertex2f(tri[0].x, tri[0].y);
    glVertex2f(tri[1].x, tri[1].y);
    glVertex2f(tri[3].x, tri[2].y);
glEnd();


What was wrong with LibGDX's triangulator (EarClippingTriangulator) and their ShapeRenderer class? Or PolygonSpriteBatch? Probably a lot easier and also more performant.

Author:  LosTChG [ Sat Jan 05, 2013 12:35 pm ]
Post subject:  Re: BUG: Filling a curved closed shape problems

In libgdx you cannot set the stroke width, that's all.
I've seen that you also abandoned slick development, that's a pity :(
Thanks for the pseudocode, it seems easy, I'll try that before giving up.
Oh, and surprisingly I get more FPS in my shitty intro gamescreen with slick than with libgdx, using the same number of images o.o

Author:  davedes [ Sun Jan 06, 2013 12:35 am ]
Post subject:  Re: BUG: Filling a curved closed shape problems

Generally LibGDX will perform much faster, but there are many things that could impact performance (especially if you are coming from a Java2D background, which does not translate well to OpenGL).

Since LibGDX is built on OpenGL, you can use the exact same mechanism that Slick uses:

Code:
Gdx.gl.glLineWidth(thickness);


Regardless of whether you use LibGDX or Slick, this is hardware dependent, which means it may or may not be anti-aliased, the end-caps might or might not be round, and you will be limited on how thin or wide the line thickness can be.

Author:  LosTChG [ Sun Jan 06, 2013 1:59 pm ]
Post subject:  Re: BUG: Filling a curved closed shape problems

Also, libgdx can't fill a shape made of beziers (although that can be solved using the triangulator and a closed shape, but I can't find a shape class in libgdx API or something similar)

Author:  davedes [ Mon Jan 07, 2013 3:52 am ]
Post subject:  Re: BUG: Filling a curved closed shape problems

That problem also exists in Slick... :wink:

Author:  LosTChG [ Mon Jan 07, 2013 12:13 pm ]
Post subject:  Re: BUG: Filling a curved closed shape problems

Uhmm, maybe xD, but how do I get the segment points of the curves generated by shaperenderer in order to make an actual shape? (Which I pressume it is just an array of points in certain order)

Author:  LosTChG [ Tue Jan 08, 2013 4:51 pm ]
Post subject:  Re: BUG: Filling a curved closed shape problems

Nevermind, I've been researching about meshes and I think you're right: though difficult, at the end it will be a benefit to do it that way.
Thanks for all!

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/