fky*_*fky 5 android multitexturing opengl-es-2.0 libgdx spritebatch
我很高兴使用LibGDX Framework的SpriteBatch类.我的目标是通过着色器修改精灵的表示.
batch = new SpriteBatch(2, shaderProgram);
Run Code Online (Sandbox Code Playgroud)
我从SpriteBatch类中复制了默认着色器,并添加了另一个统一的Sampler 2d
+ "uniform sampler2D u_Texture2;\n"//
Run Code Online (Sandbox Code Playgroud)
是否有一种工作方式将纹理赋予着色器.这样做,总是在ClearColor屏幕中结束.
batch.begin();
texture2.bind(1);
shaderProgram.setUniformi("u_Texture2", 1);
batch.draw(spriteTexture,positions[0].x,positions[0].y);
batch.draw(spriteTexture,positions[1].x,positions[1].y);
batch.end();
Run Code Online (Sandbox Code Playgroud)
每个纹理都在工作.在Mesh类的帮助下手动绘制按预期工作.那么我该怎么做才能使用SpriteBatch的便利呢?
THX寻求帮助
我猜那里的问题与纹理绑定有关.SpriteBatch假设活动纹理单元为0,因此它会调用
lastTexture.bind(); 代替 lastTexture.bind(0);
问题是你给它的主动单元是1(你texture2.bind(1);在代码中调用).因此,纹理单元0永远不会被绑定,并且可能是导致空白屏幕的因素.
例如,我会Gdx.GL20.glActiveTexture(0);在draw通话前添加一个.我不太确定它会解决问题,但这是一个开始!
编辑: 我尝试我的建议解决方案,它的工作原理!:d.为了更清楚,你应该这样做:
batch.begin();
texture2.bind(1);
shaderProgram.setUniformi("u_Texture2", 1);
Gdx.gl.glActiveTexture(GL10.GL_TEXTURE0);//This is required by the SpriteBatch!!
//have the unit0 activated, so when it calls bind(), it has the desired effect.
batch.draw(spriteTexture,positions[0].x,positions[0].y);
batch.draw(spriteTexture,positions[1].x,positions[1].y);
batch.end();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2904 次 |
| 最近记录: |