简体   繁体   中英

Error trying to get a pixmap from a texture (libGDX)

I have a texture that comes right out of a FrameBuffer via getColorBufferTexture() method. The texture is fine, though vertically flipped as expected, I can draw it in a batch without problems.

I am trying to add it to a PixmapPacker because I want to save it for further use, but I am getting an exception "This TextureData implementation does not return a Pixmap" that I do not know how to overcome.

This is the code involved in the crash:

    if (!frameBuffer.getColorBufferTexture().getTextureData().isPrepared())
        frameBuffer.getColorBufferTexture().getTextureData().prepare();
    packer.pack("panel_cells", frameBuffer.getColorBufferTexture().getTextureData().consumePixmap());

As you see, I've tried calling prepare() first, but it turned out the texture is always prepared at this point (hence the "if" first), so that's not the problem. Anyway I have left those two lines of code there just in case...

Thanks in advance!

It seems I've finally solved this issue by overriden the following method when creating the FrameBuffer:

FrameBuffer frameBuffer = new FrameBuffer(Pixmap.Format.RGBA8888, bufferSize, bufferSize, false) {
        @Override
        protected Texture createColorTexture() {
            PixmapTextureData data = new PixmapTextureData(new Pixmap(width, height, format), format, false, false);
            Texture result = new Texture(data);
            result.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
            result.setWrap(Texture.TextureWrap.ClampToEdge, Texture.TextureWrap.ClampToEdge);
            return result;
        }
    };

Now I am having problems with the packer, but that's a different story... at least I can get the texture.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM