4

I am using LibGDX for a small app project, and I need to somehow take a series of sprites and place them (or their pixels rather) into a Pixmap. The basic idea is to take random sprites that are generated through various means while the app is running, and, only at specific times, merge some of them onto a single background sprite.

I believe that most of this can be done easily, but the step of getting the sprite images into the Pixmap isn't quite so obvious to me. The sprites also have various transparent and semi-transparent pixels, so simply grabbing the color at each pixel while it is all on the same screen isn't really applicable either, as it obviously shouldn't take the background colors with it.

If there is a suitable alternative to this that would accomplish what I am looking for I would also love to hear it. Any help is highly appreciated.

Shamrock
  • 436
  • 1
  • 8
  • 17

1 Answers1

3

I think you want to render your sprites to an off-screen buffer (called an "FBO" or FrameBuffer in libgdx) (blending them as they're added), and then render that offscreen buffer to the screen as a single draw call? If so, this question should help: libgdx SpriteBatch render to texture

This requires OpenGL ES 2.0, which will eliminate support for some older devices.

Community
  • 1
  • 1
P.T.
  • 24,557
  • 7
  • 64
  • 95
  • Well, FBO's do sound about right for me, but none of my experiments with them in my current setup have proven very successful (Granted I don't know much about OpenGL and may just be doing things wrong). In addition, I'd like to actually have the pixel data in a Pixmap somehow as that seems to be the best way to be able to modify them on a pixel by pixel basis as I would like to be able to from time to time. – Shamrock Jul 05 '12 at 23:35
  • If you're going to be accessing pixels on the CPU, and you're generating these textures on the CPU, then you should probably just composite them yourself on the CPU and avoid OpenGL entirely? – P.T. Jul 06 '12 at 00:50
  • Well, it would make sense, but I believe doing that successfully for the complex setup I am trying to achieve would be a bit over my head at the moment. The main reason for wanting them in a Pixmap is for the ability to selectively remove specific areas, but I am sure this is also possible going the FBO route in a different fashion. I think right now the thing preventing it from working is my lack of knowledge in the area, so I will work at it a bit more and see if I can get something more promising going. – Shamrock Jul 06 '12 at 02:06