I think the problem here is blending. Pixmap.setBlending() is set to SourceOver
by default. That means drawing a rectangle of alpha 0 results in no change at all, since you draw an invisible rectangle. Try setting it to Pixmap.Blending.None
to really cut out the rectangle.
// Initially, the mask should have an alpha of 1
Pixmap mask = new Pixmap(128, 128, Pixmap.Format.Alpha);
// Cut a rectangle of alpha value 0
mask.setBlending(Pixmap.Blending.None);
mask.setColor(new Color(0f, 0f, 0f, 0f));
mask.fillRectangle(0, 0, 32, 32);
Pixmap fg = new Pixmap(Gdx.files.internal("foreground.png"));
fg.drawPixmap(mask, fg.getWidth(), fg.getHeight());
mask.setBlending(Pixmap.Blending.SourceOver);
Texture foreground = new Texture(fg);
Texture background = new Texture("background.png");
Actually you don't even need to create a mask, but you could directly "cut out" the rectangle on the foreground pixmap.