【问题标题】:Libgdx Does SpriteBatch draws to StencilBuffer?Libgdx SpriteBatch 是否绘制到 StencilBuffer?
【发布时间】:2012-10-03 21:48:59
【问题描述】:

我正在使用带有 OpenGL ES 1.0 的 libgdx,我想知道 SpriteBatch 是否可以写入/绘制到模板缓冲区。我一直在尝试写入它,但我根本没有得到任何结果,我没有使用模板缓冲区的经验,但我已经阅读了很多,所以如果我在接下来的任何事情中错了,请纠正我。基本上我想要做的是将带有 SpriteBatch 的纹理绘制到模板缓冲区,所以当我绘制其他东西时(禁用模板缓冲区)它只会在模板缓冲区等于 1 的区域上绘制。

这是我想要的结果: 如果我在模板缓冲区中绘制星形纹理,然后在颜色缓冲区中绘制红色纹理,我希望红色纹理忽略模板缓冲区中星形所在的像素。

这是我目前的代码:

   batch.begin();
   Gdx.gl10.glEnable(GL10.GL_STENCIL_TEST);
   Gdx.gl10.glEnable(GL10.GL_ALPHA_TEST);
   Gdx.gl10.glStencilFunc(GL10.GL_ALWAYS, 0x1, 0xffffffff);
   Gdx.gl10.glStencilOp(GL10.GL_REPLACE, GL10.GL_REPLACE, GL10.GL_REPLACE);
   Gdx.gl10.glColorMask(false, false, false, false);

   batch.draw(myShape, 100, 100); //draw to the stencil buffer a shape (texture region)

   batch.end();
   batch.begin();

   Gdx.gl10.glColorMask(true, true, true, true);
   Gdx.gl10.glStencilOp(GL10.GL_KEEP, GL10.GL_KEEP, GL10.GL_KEEP);

   // draw where the shape has NOT been drawn
   Gdx.gl10.glStencilFunc(GL10.GL_NOTEQUAL, 0x1, 0xff);

   batch.draw(BackGroundLayer, 0, 0);// draw background

   Gdx.gl10.glDisable(GL10.GL_STENCIL_TEST);

【问题讨论】:

    标签: java opengl-es libgdx stencil-buffer


    【解决方案1】:

    是的 spriteBatch 确实写入模板缓冲区,问题是我必须配置模板缓冲区。完成的方法是创建一个应用程序配置对象,并在初始化应用程序时将其作为参数传递,如下所示:

    对于 android 启动器,您需要这样做:

    AndroidApplicationConfiguration Configuration = new  AndroidApplicationConfiguration();
    Configuration.stencil = 8;  //stencil buffer size
    initialize(new Game(), Configuration);   //pass it as parameter  
    

    对于桌面是这样的

    LwjglApplicationConfiguration Configuration = new  LwjglApplicationConfiguration();
    Configuration.stencil = 8;
    new LwjglApplication(new Game(), Configuration);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-12
      • 1970-01-01
      • 2013-12-04
      • 1970-01-01
      • 2018-04-14
      • 1970-01-01
      • 2014-05-10
      • 2015-02-11
      相关资源
      最近更新 更多