3

Some quick background here, I just started using the LibGDX framework for my first attempts at Android game development. I am trying to build a texture using their FrameBuffer class by placing in sprites, and I want to use this texture as a sort of level-by-level dynamic/random background.

Unfortunately, it seems that when the sprites are added to the FrameBuffer, they will completely overwrite anything beneath them. In general this is fine, however many of the sprites I will be using for this have semi-transparent pixels, and because these transparent pixels will overwrite any solid pixels beneath them, it shows through to the base background color and produces a very unpleasant effect.

In other words, what is the best way to go about creating one solid texture out of multiple sprites, and layer them on top of each other without completely removing the lower pixels (At least if the top pixel is semi-transparent)?

Having experimented and searched for quite a few hours on this, I am at a loss. Thanks for your time!

----- edit -----

Here is the code used to add the sprite(s) to the FBO. It is extremely lacking because, for now, I am simply adding one sprite in random locations for testing purposes. I'll be happy to post any code on request, but the entire setup is extremely minimalistic right now to work on this problem.

    m_fbo.begin();
    batch.begin();
    batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    sprite.draw(batch);
    batch.end();
    m_fbo.end();
Chime
  • 51
  • 1
  • 4
  • Can you show the code you're using to add sprites to the framebuffer? – Tim Aug 14 '12 at 23:27
  • I added the code, though it is nothing excessive in the least. I am simply splattering a single sprite around at random positions for testing. I also tried quite a few combinations with blend modes, but it doesn't seem like it can be solved quite that easily. – Chime Aug 14 '12 at 23:36
  • The texture that you're drawing to, is it ever supposed to have any transparent pixels? I think the problem might be that you're drawing pixels with low alpha onto the framebuffer such that they will be blended, but if you leave blending on, then the resulting texture will *also* be blended with whatever surface you put it on top of. Do you disable blending when finally drawing the FBO texture? – Tim Aug 15 '12 at 03:27
  • I need blending enabled, as the sprites that are being added to this background texture do need to have the transparent pixels. I don't have anything permanently set yet, but think of something like clouds, which would look slapped on if I removed all of the transparent pixels along its edges. – Chime Aug 15 '12 at 03:58

1 Answers1

0

Old question, but can you paste the FBO initialization code? You need to have an alpha channel in the FBO. Another thing is that FBOs are GLES 2.0 features, so you might want to use a shader of your own, since alpha testing must be done manually on GLES 2.0.

Finally, did you enable blending on the batch?

batch.enableBlending();

should do the trick.

Jp Lorandi
  • 113
  • 1
  • 3