Well I try to render a overlay for my screen into a texture. Now I want this texture to have a transparent background. However
offView.setBackgroundColor(new ColorRGBA(0,0,0,0));
still renders the background as black.
Is there a way to force the background of the rendered texture to be transparent, so only the scene is visible on the texture?
Code:
offCamera = new Camera(screenresx, screenresy);
offView = ClientApplication.getInstance().getRenderManager().createPreView("Offscreen View", offCamera);
offView.setClearFlags(true, true,true);
// create offscreen framebuffer
offBuffer = new FrameBuffer(screenresx, screenresy, 1);
// setup framebuffer's cam
offCamera.setFrustumPerspective(45f, 1f, 1f, 1000f);
offCamera.setLocation(new Vector3f(0f, 0f, 50f));
offCamera.lookAt(new Vector3f(0f, 0f, 0f), Vector3f.UNIT_Y);
// setup framebuffer's texture
Texture2D offTex = new Texture2D(screenresx, screenresy, Format.ABGR8);
offTex.setMinFilter(Texture.MinFilter.NearestNoMipMaps);
offTex.setMagFilter(Texture.MagFilter.Nearest);
// setup framebuffer to use texture
offBuffer.setDepthBuffer(Format.Depth);
offBuffer.setColorTexture(offTex);
// set viewport to render to offscreen framebuffer
offView.setOutputFrameBuffer(offBuffer);
offView.setBackgroundColor(new ColorRGBA(0,0,0,1));
offView.attachScene(sceneNode);
guiNode.setLocalTranslation(0, 0, 20);
guiNode.setQueueBucket(Bucket.Gui);
sceneNode.attachChild(guiNode);
Quad mesh = new Quad(screenresx,screenresy);
guiBridge = new Geometry("guibridge",mesh);
guiBridge.setLocalTranslation(0, 0, 20);
guiBridge.setCullHint(CullHint.Never);
guiBridge.setShadowMode(ShadowMode.Off);
guiBridge.setQueueBucket(Bucket.Gui);
Material mat = new Material(ClientApplication.getInstance().getAssetManager(), "matdef/GuiBridge.j3md");
mat.setTexture("ColorMap", offTex);
guiBridge.setMaterial(mat);
ClientApplication.getInstance().addUpdateSceneGraphListener(this);</div>