Libgdx creates a texture from an overlay using pixmap

I am trying to create a method that returns an overlay modified texture using libgdx and PixMap.

Assuming I have 2 images: Base image in FileHandle textureInput enter image description here

And overlay image in FileHandle overLay

enter image description here

It should produce this texture:

enter image description here

Thus, it should use the RGB values ​​from the textureInput values ​​and the alpha values ​​from overLay and create the final image. I believe that I can do this using the Pixmap class, but I just can't find how.

Here is what I collect should be the structure of the method:

public Texture getOverlayTexture(FileHandle overLay, FileHandle textureInput){
    Pixmap inputPix = new Pixmap(textureInput);
    Pixmap overlayPix = new Pixmap(overLay);

    Pixmap outputPix = new Pixmap(inputPix.getWidth(), inputPix.getHeight(), Format.RGBA8888);

    // go over the inputPix and add each byte to the outputPix
    // but only where the same byte is not alpha in the overlayPix

    Texture outputTexture =  new Texture(outputPix, Format.RGBA8888, false);

    inputPix.dispose();
    outputPix.dispose();
    overlayPix.dispose();
    return outputTexture;
}

I'm just looking a bit about where to go from here. Any help is really appreciated. I apologize if this question is too vague or my approach is completely disconnected.

Thanks!

+4
1

- .

, . spritebatch . . , . . . - :

, -:

public void render(SpriteBatch batch, int renderLayer) {
    if(renderLayer == Integer.parseInt(render_layer)){              // be in the correct render layer
        batch.draw(item.region, 
                item.position.x,                                    // position.x 
                item.position.y,                                    // position.y
                0,                                                  //origin x 
                0,                                                  //origin y
                item.region.getRegionWidth() ,                      //w 
                item.region.getRegionHeight(),                      //h
                item.t_scale,                                       //scale x
                item.t_scale,                                       //scale y
                item.manager.radiansToDegrees(item.rotation));      //angle
    }
}

, , , , , .

, : https://gist.github.com/mattdesl/6076846 - , , , , :

public void render(SpriteBatch batch, int renderLayer) {
    if(renderLayer == Integer.parseInt(render_layer)){
        batch.enableBlending();

        //draw the alpha mask
        drawAlphaMask(batch, item.position.x, item.position.y, item.region.getRegionWidth(), item.region.getRegionHeight());

        //draw our foreground elements
        drawForeground(batch, item.position.x, item.position.y, item.region.getRegionWidth(), item.region.getRegionHeight());
        batch.disableBlending();
    }
}

TextureRegion alphaMask, . , /:

A "beam"

, :

private void drawAlphaMask(SpriteBatch batch, float x, float y, float width, float height) {
    //disable RGB color, only enable ALPHA to the frame buffer
    Gdx.gl.glColorMask(false, false, false, true);

    // Get these values so I can be sure I set them back to how it was
    dst = batch.getBlendDstFunc();
    src = batch.getBlendSrcFunc();

    //change the blending function for our alpha map
    batch.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ZERO);

    //draw alpha mask sprite
    batch.draw(alphaRegion, 
            x,                                                  // position.x 
            y,                                                  // position.y
            0,                                                  // origin x 
            0,                                                  // origin y
            alphaRegion.getRegionWidth(),                       // w 
            alphaRegion.getRegionHeight(),                      // h
            item.t_scale,                                       // scale x
            item.t_scale,                                       // scale y
            item.manager.radiansToDegrees(item.rotation));      // angle
    //flush the batch to the GPU
    batch.flush();
}

"" . spriteRegion. , :

enter image description here

, drawForeground, , :

private void drawForeground(SpriteBatch batch, float clipX, float clipY, float clipWidth, float clipHeight) {
    //now that the buffer has our alpha, we simply draw the sprite with the mask applied
    Gdx.gl.glColorMask(true, true, true, true);
    batch.setBlendFunction(GL10.GL_DST_ALPHA, GL10.GL_ONE_MINUS_DST_ALPHA);

    batch.draw(spriteRegion, 
            clipX,                                      // corrected center position.x 
            clipY,                                      // corrected center position.y
            0,                                                  //origin x 
            0,                                                  //origin y
            spriteRegion.getRegionWidth() ,                         //w 
            spriteRegion.getRegionHeight(),                             //h
            item.t_scale,                                       //scale x
            item.t_scale,                                       //scale y
            item.manager.radiansToDegrees(item.rotation));      //angle


    //remember to flush before changing GL states again
    batch.flush();

    // set it back to however it was before
    batch.setBlendFunction(src, dst);
}

"Brick Beams" ( - ) :

enter image description here

Android GWT ( libgdx) - .

: https://github.com/libgdx/libgdx/wiki/Integrating-libgdx-and-the-device-camera

Android, MainActivity.java onCreate :

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
    cfg.useGL20 = false;
    cfg.r = 8;
    cfg.g = 8;
    cfg.b = 8;
    cfg.a = 8;
    initialize(new SuperContraption("android"), cfg);

    if (graphics.getView() instanceof SurfaceView) {
        SurfaceView glView = (SurfaceView) graphics.getView();
        // force alpha channel - I'm not sure we need this as the GL surface
        // is already using alpha channel
        glView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
    }
}

Android.

, gwt, , libgdx GWT, webGl, -. , - (, , ).

- , GWT, .

GWT, :

https://supercontraption.com/assets/play/index.html

+4

All Articles