How to fade a texture image in JME2?

I’m using JME2 and I have the following code:

Texture camTexture = new Texture2D();
            camTexture.setMagnificationFilter( MagnificationFilter.Bilinear );
            camTexture.setMinificationFilter( MinificationFilter.BilinearNoMipMaps );
            camTexture.setImage( TextureManager.loadImage( Resources.getImage( "camera.png" ), false ) );
            TextureState textureState = display.getRenderer().createTextureState();
        	textureState.setTexture( camTexture );
        	textureState.setEnabled( true );
            _cameraImage = new Quad( "cameraImage", 64, 64 );
            _cameraImage.setLightCombineMode( LightCombineMode.Off );
            _cameraImage.setLocalTranslation( new Vector3f( 100, 100, 0 ) );
            _cameraImage.setLocalScale( new Vector3f( 1f, -1f, 1.f ) );
            _cameraImage.setRenderState( textureState );
            _cameraImage.setRenderQueueMode( Renderer.QUEUE_ORTHO );	        	
            _sceneElements.attachChild( _cameraImage );
            _sceneRoot.attachChild( _sceneElements );

I would like to control the visibility of this quad by fading it in and out. ie ramp the alpha value from 0 to 1.0 when I want to show it, and go from 1.0 to 0 when I want to hide it.

My problem is that I can’t seem to figure out how to implement that in code. Can someone help?

Check this site out.

It talks about how you can affect colors in java, rotating, scaling, translation, and alpha. It may help.

This doesn’t help me. I need to know how to fade a texture using the jme.

Why are you still using JME2? We are already at least 2 versions ahead of that (3 and 3.1).

The company that I’m working for forked the JME2 code base and customized it for their needs. No one ever upgraded to JME3.x so that is why I’m stuck with having to use JME2.

In the article, the author states how to use a matrices in java to add a greater alpha (transparent) variable to the picture. you can isolate the texture and slowly make it transparent by increasing the alpha variable. I believe the more transparent it becomes, the more faded it is.

There should be a better way to handle this in JME using blend states? I don’t want to update each pixel’s alpha value and then rebind the new texture to the quad when changing the transparency of the texture. That would be really slow. There should be an easy way to control the overall alpha of the texture, I just don’t know the architecture of JME well enough to know how to implement the desired effect.

Unfortunately, I’m not sure anyone else does either.

I’ve been answering posts on this forum for about 6 years now and JME2 is before my time. I suspect most other users have moved on, too, unfortunately (for your issue).

I’m sure there is a way to do what you want to do… but I have no idea how to do it.

And how would you handle this in JME3 ? Perhaps I can find something similar in the JME2 source code if I know what to look for.

In JME3…

Setting up to display any transparent or semi-transparent texture:
-set blend mode to alpha on the material’s additional render state
-put the spatial in the transparent bucket

To fade it:
-make sure the UseMaterialColors Material parameter is set to true.
-set the “DiffuseColor” material parameter to white with an alpha value of the desired alpha… it will be multiplied with the texture.

I don’t know how many parallels there are with JME2. But that’s the general idea, I guess. mix the texture with a white color, fade using the color’s alpha.

1 Like

As far as I remember, you can write shaders in GLSL with jME2.
Write a simple shader that multiplies the fragment with an alpha parameter.
AdditionalRenderState and transparent bucket should already been available in jME2.
I have some memories … but they are (haha) fading away…

I’m also interested in the original jME2 codebase (and jME1 too).
It would be very nice to just have that (for archive and historical research).

Since your company forked jME2 - the code might differ from the jME2 master.

Have you looked into Ardor3D continuation?
That’s another fork which was used by the NASA (I think) and other customers.
There is a developer here in the forum who manages that code (but can’t remember the name right now).


I forgot about Ardor3D. I’ll have to look into that. Thanks for the suggestions!