Altering an already bound texture

I’m interested in altering a texture slightly before drawing in, and it’s part of a texture atlas. I’d like to tint the sprite a little bit, that’s all.

I’m seeing this in Minecraft with the grass and leaves, that’s why I’m asking - How is that achieved?

I’m using Slick2D but that’s really not important for the question. I’d like to use the speed of drawEmbedded(), but the Graphics context screws up when I’m tinting my sprite.

** EDIT: This answer is more OpenGL than Slick oriented **

If it’s a solid tint over the entire quad/triangle, you can do it with the texture environment and color of the vertices. Just set the environment to MODULATE and change the vertex color and you should see a tint without having to mutate the texture object (this also means you can tint different meshes separately without re-tinting the texture).

You can also use the BLEND and BLEND_COLOR environment options to specifically tint the texture regardless of what the vertex color has been configured as.

In Slick you tint images like so:

Color.green.bind(); //can be any color object

//now the sprite will be tinted green
mySprite.drawEmbedded(x, y, width, height);

By default this uses GL_MODULATE – so each pixel in your texture will be multiplied by your vertex color, e.g. green (R=0, G=1, B=0).

For other modes (such as GL_ADD) you should read up on “Texture Combiners.”

If you want to “reset” your tinting, use this:
[icode]
Color.white.bind();
[/icode]

Beautiful guys! Thank you so much. :slight_smile: