Slick Forums

Discuss the Slick 2D Library
It is currently Thu Oct 18, 2018 4:41 am

All times are UTC




Post new topic Reply to topic  [ 11 posts ] 
Author Message
PostPosted: Tue Nov 20, 2012 12:35 am 
Offline

Joined: Mon Nov 19, 2012 10:53 pm
Posts: 7
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!


Top
 Profile  
 
PostPosted: Wed Nov 21, 2012 6:09 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1482
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


Top
 Profile  
 
PostPosted: Wed Nov 21, 2012 7:51 pm 
Offline

Joined: Mon Nov 19, 2012 10:53 pm
Posts: 7
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


Top
 Profile  
 
PostPosted: Fri Jan 04, 2013 1:18 am 
Offline

Joined: Mon Nov 19, 2012 10:53 pm
Posts: 7
It would be very difficult to implement poly2tri triangulator in Slick? It would solve all my problems :D


Top
 Profile  
 
PostPosted: Sat Jan 05, 2013 1:19 am 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1482
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.


Top
 Profile  
 
PostPosted: Sat Jan 05, 2013 12:35 pm 
Offline

Joined: Mon Nov 19, 2012 10:53 pm
Posts: 7
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


Top
 Profile  
 
PostPosted: Sun Jan 06, 2013 12:35 am 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1482
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.


Top
 Profile  
 
PostPosted: Sun Jan 06, 2013 1:59 pm 
Offline

Joined: Mon Nov 19, 2012 10:53 pm
Posts: 7
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)


Top
 Profile  
 
PostPosted: Mon Jan 07, 2013 3:52 am 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1482
That problem also exists in Slick... :wink:


Top
 Profile  
 
PostPosted: Mon Jan 07, 2013 12:13 pm 
Offline

Joined: Mon Nov 19, 2012 10:53 pm
Posts: 7
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)


Top
 Profile  
 
PostPosted: Tue Jan 08, 2013 4:51 pm 
Offline

Joined: Mon Nov 19, 2012 10:53 pm
Posts: 7
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!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group