admin管理员组文章数量:1279242
I am making a game, in which I want to cover the background from the player and show just few fragments of the background - eg. area around the player and one or two brightened areas. So the masking process of covering texture has to be made at runtime (not once prepared/masked on game start or just used as a premade png files).
Game main class:
protected Pixmap circleShadowBigPixmap;
protected Pixmap pixmapBlackCover;
protected Texture pixmapTexture;
Update class:
arrowGame.lightX++;
arrowGame.pixmapBlackCover.setBlending(Pixmap.Blending.None); // before you start drawing pixels.
arrowGame.pixmapBlackCover.drawPixmap(arrowGame.circleShadowBigPixmap, arrowGame.lightX, 500);
arrowGame.pixmapBlackCover.setBlending(Pixmap.Blending.SourceOver);
arrowGame.pixmapTexture.draw(arrowGame.pixmapBlackCover, 0, 0);
Drawing class:
sb.draw(arrowGame.pixmapTexture, x, y); // sb - spritebatch
Preparing graphics class:
arrowGame.circleShadowBig = new Texture("shadowCircleBig.png");
arrowGame.circleShadowBig.getTextureData().prepare();
Screenshots: 1- unwanted mask fragment (this fragment shoud do nothing to the source pixmap, should be neither black nor transparent) 2- transparent area 3- black area (hidden)
I am making a game, in which I want to cover the background from the player and show just few fragments of the background - eg. area around the player and one or two brightened areas. So the masking process of covering texture has to be made at runtime (not once prepared/masked on game start or just used as a premade png files).
Game main class:
protected Pixmap circleShadowBigPixmap;
protected Pixmap pixmapBlackCover;
protected Texture pixmapTexture;
Update class:
arrowGame.lightX++;
arrowGame.pixmapBlackCover.setBlending(Pixmap.Blending.None); // before you start drawing pixels.
arrowGame.pixmapBlackCover.drawPixmap(arrowGame.circleShadowBigPixmap, arrowGame.lightX, 500);
arrowGame.pixmapBlackCover.setBlending(Pixmap.Blending.SourceOver);
arrowGame.pixmapTexture.draw(arrowGame.pixmapBlackCover, 0, 0);
Drawing class:
sb.draw(arrowGame.pixmapTexture, x, y); // sb - spritebatch
Preparing graphics class:
arrowGame.circleShadowBig = new Texture("shadowCircleBig.png");
arrowGame.circleShadowBig.getTextureData().prepare();
Screenshots: 1- unwanted mask fragment (this fragment shoud do nothing to the source pixmap, should be neither black nor transparent) 2- transparent area 3- black area (hidden)
Share Improve this question edited Feb 23 at 21:56 Radek Sołdek asked Feb 23 at 21:50 Radek SołdekRadek Sołdek 531 silver badge6 bronze badges
1 Answer
Reset to default 0Finally... Used shaders
Game main class:
ShaderProgram.pedantic = false;
mask = new Texture(Gdx.files.internal("bigSun1024violet.png"));
viewMask = new Texture(Gdx.files.internal("bigSun256violet.png"));
maskBuff = new FrameBuffer(Pixmap.Format.RGBA8888, frmSizeX, frmSizeY, false);
msk = new TextureRegion(maskBuff.getColorBufferTexture());
frmBuff = new FrameBuffer(Pixmap.Format.RGBA8888, frmSizeX, frmSizeY, false);
frm = new TextureRegion(frmBuff.getColorBufferTexture());
coverSprite = new Sprite(new Texture("violetCover.png"));
float donutX = 0;
float donutY = 0;
coverSprite.setPosition(donutX, donutY);
cam.update();
// shader = new ShaderProgram(VERT, FRAG);
shader = new ShaderProgram(Gdx.files.internal("vertex.glsl"), Gdx.files.internal("fragment-video.glsl"));
if (!shader.isCompiled()) {
System.err.println(shader.getLog());
System.exit(0);
}
if (!shader.getLog().isEmpty())
System.out.println(shader.getLog());
shader.bind();
shader.setUniformi("u_texture1", 1);
shader.setUniformi("u_mask", 2);
defaultShader = spriteBatch.getShader();
//bind mask to glActiveTexture(GL_TEXTURE2)
msk.getTexture().bind(2);
//bind dirt to glActiveTexture(GL_TEXTURE1)
// tex1.bind(1);
frm.getTexture().bind(1);
//now we need to reset glActiveTexture to zero!!!! since sprite batch does not do this for us
Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0);
Update class:
arrowGame.lightX--;
arrowGame.maskBuff.begin();
Gdx.gl.glClearColor(255, 255, 255, 255);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
arrowGame.spriteBatch.begin();
arrowGame.spriteBatch.draw(arrowGame.mask, arrowGame.lightX, 0, 0, 0, arrowGame.frmSizeX, arrowGame.frmSizeY, 1, 1, 0, 0, 0, arrowGame.frmSizeX, arrowGame.frmSizeY, false, true);
arrowGame.spriteBatch.draw(arrowGame.viewMask, 500, 500, 0, 0, 256, 256, 1, 1, 0, 0, 0, 256, 256, false, true);
arrowGame.spriteBatch.end();
arrowGame.maskBuff.end();
Drawing class:
sb.setShader(arrowGame.shader);
arrowGame.coverSprite.draw(sb);
sb.setShader(arrowGame.defaultShader);
Thanks to: https://github/raeleus/masks-example-project/blob/main/core/src/main/java/com/ray3k/liftoff/TestShaderVideo.java
Libgdx masking with image
本文标签: libgdxMasking texture does not work as expectedStack Overflow
版权声明:本文标题:libgdx - Masking texture does not work as expected - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741301151a2371095.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论