Transparent...and Opaque!

Hey guys, I'm working on a game in jME that uses some two-dimensional images instead of models and I'm trying to figure out how to apply transparency properly to the texture.



Utilizing the following AlphaState:

        AlphaState as = DisplaySystem.getDisplaySystem().getRenderer().createAlphaState();
        as.setBlendEnabled(true);
        as.setSrcFunction(AlphaState.SB_SRC_ALPHA);
        as.setDstFunction(AlphaState.DB_ONE);
        as.setTestEnabled(true);
        as.setTestFunction(AlphaState.TF_GEQUAL);
        as.setEnabled(true);



I end up with:



I am trying to end up with the background color to disapear and the main image to remain.  That is happening sort of, except the main image is translucent, I want it to be solid.  Can someone explain how to accomplish this?

Thanks,

darkfrog

these are my settings



AlphaState as2 = DisplaySystem.getDisplaySystem().getRenderer().createAlphaState();
       as2.setBlendEnabled(true);
       as2.setSrcFunction(AlphaState.SB_SRC_ALPHA);
       as2.setDstFunction(AlphaState.DB_ONE);
       as2.setTestEnabled(true);
       as2.setTestFunction(AlphaState.TF_GREATER);
       as2.setEnabled(true);
       setRenderQueueMode(Renderer.QUEUE_TRANSPARENT);



can you also post up the images as .png's or whatever they are if the above doesnt work

…that’s identical to the source I posted. :-p







darkfrog

? including the last line - setting the render queueQueueMode

I always use .png, that way you can have a true alpha background and set the alpha for each pixel and they are not lossy. Not sure about gifs



Think for youre prob, you dont want to blend the pixels of the apache. But, as the background is black and not transparent you cannot simply replace the pixel. Try changing the image to a png with a true transparent background - otherwise you will need to filter/skip the black pixels in the image

Converted it to PNG-24 with transparency and the body itself is still translucent.



darkfrog

Try this:



            txa.setBlendEnabled(true);
            txa.setTestEnabled(true);
            txa.setTestFunction(AlphaState.TF_GREATER);
            txa.setReference(0.9f);
            txa.setEnabled(true);



This is what i use for textures which are not translucent, but do have parts which are (wire, foliage). You can try "setBlendEnabled(false)" too.

Great job, that fixed it. :slight_smile:



Thanks!



darkfrog

Havent enough time to get you code right now - can do tommorrow if the following doesnt help



Look at the FPS font rendering - as in the ortho FPS -, from memory each letter is taken from an image which lookups where the letter is, each letter is then rendedered to the FPS Quad with bakground as alpha

I still can’t seem to get this thing to work…driving me crazy. :o



Anyone interested in helping me solve this is more than welcome to check it out from my repository. :slight_smile:



http://captiveimagination.com/svn/public/ApacheAttack/trunk



Thanks



darkfrog

Are you drawing the terrain before the alpha textured quad? The texture combine mode also affects drawing, and those combine options are quite cryptic.

I'm creating the terrain first and then the chopper.  I'll try switching them around tonight to see if that makes any difference.



darkfrog

If you are using RenderQueue, it won't make any difference.

Try these settings from the HelloMousePick tutorial:


        AlphaState as = display.getRenderer().createAlphaState();
        as.setBlendEnabled(true);
        as.setSrcFunction(AlphaState.SB_SRC_ALPHA);
        as.setDstFunction(AlphaState.DB_ONE_MINUS_SRC_ALPHA);
        as.setTestEnabled(true);
        as.setTestFunction(AlphaState.TF_GREATER);



They seem to work fine most of the time.

Nope, still won't work.  I've even swapped out my Box for Quad instead and it still doesn't like me.



I'll look more at the fps rendering and see if I can make something from that.



darkfrog

Though the probability is quite high that I'm crazy and just unable to figure out why, this is still not working for me.  I would greatly appreciate it if someone more knowledgable than myself on this could point me in the right direction as I'm not sure what else to try.



thanks!



darkfrog

croak!  :stuck_out_tongue:



try a

chopperBody.setTextureCombineMode(TextureState.REPLACE);


before setting the alpha state which (if you want the chopper to look a little bit better) should be


AlphaState alpha = display.getRenderer().createAlphaState();
alpha.setSrcFunction(AlphaState.SB_SRC_ALPHA);
alpha.setDstFunction(AlphaState.DB_ONE_MINUS_SRC_ALPHA);
alpha.setTestFunction(AlphaState.TF_GREATER);
alpha.setBlendEnabled(true);
chopperBody.setRenderState(alpha);


can you post your texture?

take a look at his trunk. there are the textures and the code.



edit: typo

It’s also referenced here:

http://www.jmonkeyengine.com/jmeforum/index.php?topic=3270.msg25122#msg25122



However, I’m currently referencing a PNG:





Thanks guys.