Transparent mouse pointer

Hello,



currently I am trying to display my own mouse pointer. I use the code provided in the mouse picking example, but my mousepointer isn't transparent -> i can see a black or white rectangle around it. I guess it has to do with the transparency of the picture I use (has no alpha channel). Is it possible to say that for example all white pixel in the pointer image should be transparent? Thats the code I use:



        absMouse = new AbsoluteMouse("my mouse", display.getWidth(), display.getHeight());
       
        URL url = this.getClass().getClassLoader().getResource("textures/cursor.png");
        //URL url = this.getClass().getClassLoader().getResource("jmetest/data/cursor/cursor1.png");
        Texture t = TextureManager.loadTexture(url, Texture.MM_LINEAR, Texture.FM_LINEAR);
        TextureState ts = display.getRenderer().createTextureState();
        ts.setTexture(t);
        absMouse.setRenderState(ts);
       
        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);
        absMouse.setRenderState(as);
        absMouse.setLocalTranslation(new Vector3f(display.getWidth() / 2, display.getHeight() / 2, 0));
       
        absMouse.registerWithInputHandler( input );
        rootNode.attachChild(absMouse);



Thx for your help!

why are you using a cursor which doesn't have an alpha channel?

Simply because I have no picture with an alphachannel. Isn't it possible to use the color white or the grayness or whatever as alpha?

Should be possible.  You'll need to use different src and dst functions on your AlphaState that reference color.

i think creating a image with an alpha channel would be the easiest solution (with gimp or something similar)

From my experience it is possible. However, becuase of how most programs have done the antialiasing you don't get good results around the pointer image itself. Often you'll end up with a pointer where all the 'true' white IS transparent, but the blends of white aren't blends to transparency, just white.

Thanks for your replies!

I made a picture with The GIMP and an alpha channel and yes, you are right. It's the easiest way.