0

Hi i need to create a texture that is made up of other textures overlayed. I've tried using pixmap however it is noticably slow. The idea is to create a "snapshot" of a dialog so that it can be animated as it shows up and when it is dismissed. Please help

This is the code that I am using:

texture_dialog.getTextureData().prepare();
Pixmap pm1 = texture_dialog.getTextureData().consumePixmap();
btn_ok.getTexture().getTextureData().prepare();
Pixmap pm = btn_ok.getTexture().getTextureData().consumePixmap();
pm1.drawPixmap(pm, pm1.getWidth()/2 - pm.getWidth()/2, pm1.getHeight() - pm.getHeight() - 52);
textureSnapShot = new Texture(pm1, true);
pm1.dispose();
pm.dispose();

textureSnapShot.setFilter(TextureFilter.MipMapLinearLinear, TextureFilter.MipMapLinearLinear);
spriteSnapShot = new Sprite(textureSnapShot);

I've tried using a FrameBuffer as follows:

SpriteBatch sb = new SpriteBatch();
sb.setProjectionMatrix(camera.combined);
FrameBuffer fbo = new FrameBuffer(Format.RGBA8888, texture_dialog.getWidth(),  texture_dialog.getHeight(), false);
            
fbo.begin();
sb.begin();
sb.draw(texture_dialog, 0, 0);
sb.draw(btn_ok.getTexture(), texture_dialog.getWidth()/2 - btn_ok.getWidth()/2, 52);
sb.end();
fbo.end();
sb.dispose();
textureSnapShot = fbo.getColorBufferTexture();
            
//textureSnapShot.setFilter(TextureFilter.MipMapLinearLinear, TextureFilter.MipMapLinearLinear);
spriteSnapShot = new Sprite(textureSnapShot);

The results are as follows: http://medialinestudio.co.za/screens.png

Left: Pixmap Right: FrameBuffer

Pixmap has the correct result but too slow. FrameBuffer is faster but incorrect result

dStulle
  • 609
  • 5
  • 24
MSD
  • 137
  • 9
  • Look into FrameBuffer (a libgdx class). – Tenfour04 Aug 09 '15 at 03:07
  • by snapshot do you mean screenshot? for faster performance us runOnUiThread() procedure I dont exactly remeber the procedure but what i meant is to dod snapshot in somw other thread – Kumar Saurabh Aug 09 '15 at 08:38
  • It looks like you're trying to solve the wrong problem. You don't need a snapshot/fbo/pixmap to animate a Dialog. Just animate the dialog, including any children it has. Assuming you're using the Dialog widget then that is already the default behavior. Otherwise you can put in a Group actor if you prefer that. – Xoppa Aug 09 '15 at 15:08
  • I think that is where i am going wrong. My components are all basic texture not widgets. However im gone too far using this method to go back and change :(.. i guess ill just have to do with the lag. Just as a reference is there no other way to combine textures into a new texture? – MSD Aug 09 '15 at 17:10

1 Answers1

0

FBO is definitely what you should use for your need.

read this post : libgdx SpriteBatch render to texture

what you missing is :

  • create a camera with correct width/height and position to fit your drawing inside the FBO viewport (0,0,Width,Height)
  • flip the output texture (m_fboRegion.flip(false, true))
Community
  • 1
  • 1
mgsx-dev
  • 440
  • 3
  • 5
  • I am using an ortographic camera. When i set the projection matrix to combined the resulting image is squashed. Another issue with fbo is that when setting mipmaps to true on the underlying texture of the frame buffer a blank texture is produced – MSD Aug 09 '15 at 22:37
  • Fbo also requires the texture to be recreated everytime the screen is resized. pixmap is slower but is definitely less troublesome – MSD Aug 09 '15 at 22:42
  • I think you should read more tutorials about FBO : your matrix setup is maybe wrong, render to texture with mipmaps needs more work and yes FBO has a fixed size so you need to recreate if your texture size have to change. – mgsx-dev Aug 10 '15 at 16:51