3

I wonder know how to get the FrameBufferPixel in a Pixmap

I know I must use getFrameBufferPixels(true)

But I don't know what parameters to put in

new Pixmap(byte[] encodedData, int offset, int len);

Can you show me an exemple who should works ?

Thanks you

LeSam
  • 1,235
  • 4
  • 18
  • 38
  • A Pixmap represents a texture in regular memory, a FrameBuffer represents a render target as a texture. There are no "FrameBufferPixel" for a Pixmap. Can you describe what you're trying to do more generally? – P.T. May 26 '13 at 01:07
  • 1
    I want to have a Screenshot of the game in a Pixmap – LeSam May 26 '13 at 01:27
  • I want to put a screenshot of my game in a Pixmap for give it a Blur Script wich works only on Pixmap. – LeSam May 26 '13 at 02:07

1 Answers1

8
new Pixmap(byte[] encodedData, int offset, int len);

As far as I know, encodedData needs to hold data from a png, jpg or bmp file, including the file header. The data you receive from getFrameBufferPixels is in RGBA8888 format. So you can't use this constructor for your screenshot. Instead I would try something like this:

byte[] pixelData = ScreenUtils.getFrameBufferPixels(true);
Pixmap pixmap = new Pixmap(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), Format.RGBA8888);
ByteBuffer pixels = pixmap.getPixels();
pixels.clear();
pixels.put(pixelData);
pixels.position(0)
Shinni
  • 241
  • 1
  • 5
  • ok, but I want that the screenshot be in the Pixmap for give it a blur script, and with your code, the Pixmap you created stay empty... Can you give me a complete code please. – LeSam May 26 '13 at 15:22
  • I also tried this http://code.google.com/p/libgdx-users/wiki/Screenshots for put the screenshot into a Pixmap and it doesn't work, it shows a Blue screen with 0.5 alpha... BUT When I save the picture, It works.. BUT I don't want to save the picture.. I just want the pixmap. – LeSam May 26 '13 at 15:35
  • 2
    I made a small project. It draws an image once and takes a screenshot afterwards. That screenshot is then converted back to a texture and drawn 3 times to prove it's not empty. https://dl.dropboxusercontent.com/u/3504939/ScreenshotTest.rar – Shinni May 26 '13 at 19:03
  • Thanks you, you re right, I did a mistake, your code works perfect ! – LeSam May 26 '13 at 20:24
  • I guess that ScreenUtils.getFrameBufferPixels relies only on the FrameBuffer on the screen. How would you do the same for a FrameBuffer object you have created on your own? – Fran Marzoa Oct 10 '16 at 09:36