Drawing with true alpha

Started by aZen, March 04, 2014, 12:48:02 AM

Previous topic - Next topic

aZen

I've tried:

        Config.useFramebufferWithAlpha = true;
        FrameBuffer fb = new FrameBuffer(getWidth(), getHeight(), FrameBuffer.SAMPLINGMODE_OGSS);
        fb.clear(new Color(255,255,255,0));
        world.renderScene(fb);
        world.draw(fb);
        fb.update();
        BufferedImage result = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
        fb.display(result.getGraphics());
        Config.useFramebufferWithAlpha = false;
        return result;


But the alpha value is only "1" or "0", so the edges don't appear smooth. Is there an easy way to fix this?

EgonOlsen

It should work already if your textures have a real alpha channel, i.e. have been created by using the Texture constructor with the useAlpha flag (and out of a file format that actually supports alpha like png).

aZen

I should have clarified: I'm using oversampling (FrameBuffer.SAMPLINGMODE_OGSS). So I'm expecting the edges where the background and the object are anti-aliased to blend smoothly. At the moment the transparency is either 1 or 0. I was hoping it would blend as 0 to 255.

EgonOlsen

I see...that's something completely different. I'll have a look...

EgonOlsen

Try this jar: http://jpct.de/download/beta/jpct.jar

The current behaviour is by design, so i'm not going to change it. But i added a config switch, Config.blendAlphaIfOversampling. Set it to true and see if that helps.

aZen

Thank you! Unfortunately it's still not correct. It appears that the pixels are first blended with the background and then the alpha transparency is applied.

If this is problematic to implement on your end I can always do two render passes with black and white and calculate the correct transparency and color myself.


(left with black background and right with white background, you can see the white pixels in the right image)

EgonOlsen

Opps...yes, you are right. I've updated the jar, but i've no idea if that version works better or colors everything like a rainbow. If it still doesn't work, maybe you can provide me with a simple test case?

aZen

Quote from: EgonOlsen on March 04, 2014, 10:03:09 PM
[...] no idea if that version works better or colors everything like a rainbow [...]

Haha, those are great alternatives =)
Everything seems to work fine now! Thank you very much!