Slick Forums

Discuss the Slick 2D Library
It is currently Mon Apr 21, 2014 2:11 am

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: RFE: Advanced Gradients.
PostPosted: Fri Nov 16, 2007 1:42 am 
Offline

Joined: Sun Feb 11, 2007 9:25 pm
Posts: 92
I was trying to get advanced gradients working, with a use syntax like...
Code:
      gradient = new AdvancedGradientFill(0, -75, 0, 75);
      gradient.addColor(0.0f, Color.red);
      gradient.addColor(.5f, Color.yellow);
      gradient.addColor(1f, Color.blue);


I actually got this working, however, because of the way ShapeRenderer draws, it doesn't work, even with the AdvancedGradientFill class implementing ShapeFill because it will draw a shape with the least amount of verticies possible.

Is there a way we could have this work by splitting up the shape being drawn using the new SVG Triangulator stuff, and then using the triangluated polygon to draw the shape?

Sure, it would use a lot more polygons, but it would make this feature work well, and with the new display lists function added to slick, it might not be a big performance hit.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 16, 2007 2:18 am 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1482
I would love this feature if it's ever possible.

Advanced gradients could make SUI much more visually impressive. :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 16, 2007 8:32 am 
Offline
Site Admin
User avatar

Joined: Thu Jan 01, 1970 12:00 am
Posts: 3143
Why not just call

public void increaseTriangulation();

On the shapes?

Kev


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 16, 2007 1:32 pm 
Offline

Joined: Sun Feb 11, 2007 9:25 pm
Posts: 92
kevglass wrote:
Why not just call

public void increaseTriangulation();

On the shapes?

Kev


Well, because that doesn't work.
The placement of the added polys doesn't make the gradient smooth.
In order for that to work, I believe it would have to make quad style triangles or something.

Here is a screenshot. The gradient attempted on the RoundedRect and Rectangle is (Red->Yellow->Red)

Without calling increaseTriangulation();
Image

Notice that the rectangle completly skips yellow, as there are no verticies to put there.

With calling increaseTriangulation();
Image


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 17, 2007 4:49 pm 
Offline
Site Admin
User avatar

Joined: Thu Jan 01, 1970 12:00 am
Posts: 3143
1) Are you sure you've got the latest code - this method was added for the New SVG stuff and went through several interations.

2) There isn't ever a perfect triangulation for every gradient/texture/pattern. You can try calling increase triangulation multiple times which should give you better and better results.

At the moment the increased triangulation is done by splitting each triangle from the original shape into 5 around the centre. This prevents any spanning lines or single point verticies. If you've got a better solution let me know, I'm not sure what "quad style triangles" are?

One useful think to try is setting glPolygonMode to LINE rather than FILL then you can actually see the triangles that are drawn.

EDIT: Saying that, SVG gradients are built into textures and used to fill the shape. So maybe that's suit your needs better?

Kev


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 17, 2007 5:40 pm 
Offline

Joined: Sun Feb 11, 2007 9:25 pm
Posts: 92
Actually, that is exactly what I need.
Rendering the gradient to a texture and then using that as a fill is the best way to do this.

Ill take a look at the SVG stuff and see if I can get this working :D


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 0 guests


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