Reputation: 684
I am creating a game with an ascii-like map using Java2D on Linux (like a roguelike).
By rendering BufferedImages via Graphics2D.drawImage the terrain is rendered. I would like to change the hue of each drawn image on the fly, without hurting performance too much. How can I achieve this?
I suspect setComposite is part of the puzzle. Currently I do not need to keep the background intact (so transparency is not an issue). I want to use a wide variety of colors, so pre-generating tinted sprites is not a solution for me.
Upvotes: 2
Views: 1231
Reputation: 684
I decided to switch to a framework that allowed more control given Tom Hawtin's answer. JOGL and LWJGL both seem to provide access to a tinting mechanic. I opted for LWJGL, as it overlaps more with my other needs.
I found this Space Invaders Tutorial useful as its a nice rosetta stone between Java2D and JOGL, LWJGL.
Here is the method I created for the LWJGL Sprite class.
public void drawTinted(int x, int y, float red, float green, float blue)
{
GL11.glPushMatrix();
texture.bind();
GL11.glTranslatef(x, y, 0);
GL11.glColor3f(red,green,blue);
GL11.glBegin(GL11.GL_QUADS);
{
GL11.glTexCoord2f(0, 0);
GL11.glVertex2f(0, 0);
GL11.glTexCoord2f(0, texture.getHeight());
GL11.glVertex2f(0, height);
GL11.glTexCoord2f(texture.getWidth(), texture.getHeight());
GL11.glVertex2f(width,height);
GL11.glTexCoord2f(texture.getWidth(), 0);
GL11.glVertex2f(width,0);
}
GL11.glEnd();
GL11.glPopMatrix();
}
Upvotes: 0
Reputation: 147164
For high performance you might want to use JOGL. It gives you good access to hardware acceleration, even if you do not need to 3D features.
Upvotes: 1
Reputation: 65550
I asked a similar question a while ago and got a pretty good answer here, although I was doing all of the tinting ahead of time. In any case, you'll probably want to look at BufferedImageOp. Also, the JH Labs site has a ton of useful info on doing image processing in java.
Upvotes: 2