Slick Forums

Tinting images on the fly
Page 1 of 1

Author:  stillwind [ Fri Jun 28, 2013 5:49 pm ]
Post subject:  Tinting images on the fly

Hi Matthias,

It's about how to tint images loaded from the theme. I have a situation where the solution I'm using works, but seems heavyweight.

I have an image (actually several of them) which gets loaded from theme and, as normal, it's a GridImage with an array of 9 TextureAreas inside it. Each of those is created in TWL with a tint colour, I load a white one from the theme, because I want to tint them.

I've been keeping a tinted version of each of the colours I need by calling createTintedVersion() on the Image returned by the theme. I thought it would be a good idea to cache these, as I could have many to draw, but the number of colours can grow (the user would create as many as they like), and so I looked at how to just store the one base white image and then use the LWJGLTexture.bind(Color) method in a call to my own version of draw... that is, add Color to the current draw() methods.

Trouble is, I'm getting deeper and deeper into your classes trying to find a way to do this, and I'm not sure how far I'd end up in order to achieve what is essentially fairly easy. The trouble is I can't get access to the LWJGLTexture to either sub-class or make my own version of a TextureArea.

So, I guess my question has 2 parts:
1) Is there already a way to draw a grid image in different colours on the fly without creating new tinted versions?
2) If there isn't, can you suggest a way for me to load an image from the theme that I can then use to make my own MutableColourTextarea or MutableColourGridImage (or similar)? Does the theme always load the same type of image, or is there a parameter that loads another type? I would really like to keep using the theme for this, as it does so much cool stuff, like breaking down the image into a grid :)

I hope all of this makes sense, essentially instead of calling draw() like this :
image.draw(animationState, x, y, w, h);

I'd like to call it like this :
image.draw(animationState, x, y, w, h, tintColor);

thanks for any help!

Author:  MatthiasM [ Fri Jun 28, 2013 6:01 pm ]
Post subject:  Re: Tinting images on the fly

Do this inside your paintWidget method:
final Renderer renderer = gui.getRenderer();
renderer.pushGlobalTintColor(r, g, b, a);
try {
   // your rendering code here
} finally {

Author:  stillwind [ Fri Jun 28, 2013 6:26 pm ]
Post subject:  Re: Tinting images on the fly


So easy... lucky I didn't find a way to do it haha

thanks a lot

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group