Combine two textures or edit a texture?


First, I was wondering if I can retrieve the image from a Texture object and edit it using Graphics2D from java, and then re-apply it.  (I know I can do the second bit, but I can't seem to figure out how i'd go about reclaiming the Image (java.awt.Image

) from the Texture, because I don't think (com.jme.image.Image) is what I'm looking for).

Alternatively, I'm wondering if it is possible to combine two textures, by drawing non transparent pixels from one onto another.  This would also solve my issue.

Thanks in advance for any help/suggestions!

i guess texture blending does what you need, have two textures and the second texture is blended onto the other. the way it is blended can be set with the various enums. Have a look at it in the wiki.

ok, so I've looked over the texture stuff in the wiki, and I see what I need to do to set up the textures to be combined (i think) by setting


and then the various other settings for combining.  What I don't see is how to actually combine them.  Is this done if I add both to a TextureState?  Do I need to set any settings on the TextureState?  This info would make a good wiki edit I think.

Actually, you are getting into the realm of actual openGL (jME just becomes an interface); check out some general openGL documentation on multitexturing (google).

(and bear with it, I have been working how all those work myself for a while…)

take a look at TestMultitexture:

    TextureState ts = display.getRenderer().createTextureState();
    Texture t1 = TextureManager.loadTexture(
    ts.setTexture(t1, 0);

    Texture t2 = TextureManager.loadTexture(TestBoxColor.class.getClassLoader().
    ts.setTexture(t2, 1);

    t.copyTextureCoordinates(0, 1, 1.0f);

this will make a fiftyfifty blend of both textures.

If you want the non-transparent parts of the second texture to replace pixels from the first texture, you set:


I dont see it like basixs that you have to know all the blending stuff just to combine two textures, but it sure as hell will help you along the way.  ;)

2 textures is easy (but get into parrallax, bump mapping, splatting etc and that knowledge is invaluable…)

but, yeah gotta start learning somewheres :slight_smile:

Multitexture/combiners are really annoying to use… Consider just creating a shader, believe it or not, even those crappy intel gmas support shaders (as assembly).

Ok, so I tried the code sample provided by dhdd…  It seems to be blacking out my Texture.

My code:

TextureState ts = (TextureState)tmTextures.get("gamedisc");
Texture t1 = ts.getTexture();  //base texture
Texture t2 = getTexture();  //texture made from a RGBA BufferedImage, consisting of some text
ts = display.getRenderer().createTextureState();
ts.setTexture(t1, 0);
ts.setTexture(t2, 1);
disc.setState("gamedisc", ts);
public boolean setState( String area, TextureState ts ) {
        if (this.discNode.getChild(area) != null) {
                ((TriMesh)this.discNode.getChild(area)).copyTextureCoords(0, 0, 1);
            return true;
        return false;

disc is a model with multiple texture "areas" (I don't know the actual term).  the disc object is a node with children (not sure the type, but casting to TriMesh isn't throwing exceptions), and you can see the method I'm using to change the textures.

Anyways I can't figure out whats going on, probably because I've just blindly copied the code in hopes it would work.  Any help or guidance would be appreciated, I'm probably missing some silly step.

((TriMesh)this.discNode.getChild(area)).copyTextureCoords(0, 1, 1);

you were copying from 0 to 0 - not that helpful  :wink: