【问题标题】:Background invisible when masking in an FBO在 FBO 中屏蔽时背景不可见
【发布时间】:2017-02-09 18:52:15
【问题描述】:

我正在尝试将前景纹理蒙版到 LibGDX 中的背景纹理上。在屏幕上绘制时效果很好,但在 FBO 中绘制时背景消失了。

以下是蒙版的绘制方式:

batch.draw(background, x, y);
batch.flush();

Gdx.gl.glColorMask(false, false, false, true);
batch.setBlendFunction(GL20.GL_ONE, GL20.GL_ZERO);
batch.draw(mask, x, y);
batch.flush();

Gdx.gl.glColorMask(true, true, true, true);
batch.setBlendFunction(GL20.GL_DST_ALPHA, GL20.GL_ONE_MINUS_DST_ALPHA);
batch.draw(foreground, x, y);
batch.flush();

batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

这是我绘制普通版和 FBO 版的方式:

常规

batch.begin();
batch.enableBlending();
batch.setProjectionMatrix(camera.combined);

drawFull(32, 600 - (64 * 4) - 32);

batch.end();

FBO

// draw the FB mask

fb.begin();
batch.begin();
batch.setProjectionMatrix(fbcamera.combined);
batch.enableBlending();

Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

drawFull(0, 0);

batch.end();
fb.end();

// draw the FB mask to the main batch

batch.begin();
batch.enableBlending();
batch.setProjectionMatrix(camera.combined);

batch.draw(fb.getColorBufferTexture(), 32, 600 - (64 * 7) - 32);

batch.end();

【问题讨论】:

    标签: java opengl libgdx


    【解决方案1】:

    我设法通过在将 FBO 绘制到屏幕时禁用混合来解决这个问题。这样做的缺点是我们无法绘制不透明的 FBO。

    // draw the FB mask to the main batch
    
    batch.begin();
    batch.disableBlending();
    batch.setProjectionMatrix(camera.combined);
    
    batch.draw(fb.getColorBufferTexture(), 32, 600 - (64 * 7) - 32);
    
    batch.end();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-24
      • 1970-01-01
      • 2012-12-19
      • 1970-01-01
      • 1970-01-01
      • 2014-01-29
      • 2020-04-24
      相关资源
      最近更新 更多