0

I am trying to make my texture region into a pixmap but by following the prepared method it is copying the whole atlas into the pixmap , so I am suggested to loop each pixel and map it into another pixmap manually

    Pixmap emptyPixmap = new Pixmap(trLine.getRegionWidth(), trLine.getRegionHeight(), Pixmap.Format.RGBA8888);

    Texture texture = trLine.getTexture();
    texture.getTextureData().prepare();
    Pixmap pixmap = texture.getTextureData().consumePixmap();

    for (int x = 0; x < trLine.getRegionWidth(); x++) {
        for (int y = 0; y < trLine.getRegionHeight(); y++) {
            int colorInt = pixmap.getPixel(trLine.getRegionX() + x, trLine.getRegionY() + y);
            emptyPixmap.drawPixel( trLine.getRegionX() + x , trLine.getRegionY() + y , colorInt );
        }
    }

    trBlendedLine=new Texture(emptyPixmap);

But the texture generated is drawing nothing , which means the getPixel is not getting the correct pixel. Please advice.

Leon Armstrong
  • 1,285
  • 3
  • 16
  • 41

1 Answers1

1

You are drawing your pixel outside of the pixmap by using the trLine.getRegionX() + x and trLine.getRegionY() + y . What you should have instead is:

for (int x = 0; x < trLine.getRegionWidth(); x++) {
    for (int y = 0; y < trLine.getRegionHeight(); y++) {
        int colorInt = pixmap.getPixel(trLine.getRegionX() + x, trLine.getRegionY() + y);
        emptyPixmap.drawPixel(x , y , colorInt );
    }
}
dfour
  • 1,376
  • 1
  • 12
  • 16
  • thats the obvious bug in my code , btw , I realise pixmap is very costly to achieve what I want , like erasing a polygon shape out of a texture – Leon Armstrong Oct 26 '17 at 14:21