我使用一个绘制一些 2D 纹理并使用它们的程序。在这个程序中使用了 libgdx。我在使用 FrameBuffer 时遇到了一些问题。我尝试在我的 FrameBuffer 中绘制一些纹理,然后我需要保存更改的纹理(或绘制)并在此 FrameBuffer 中使用该纹理更多时间。我尝试通过保存纹理
Texture texture = mFrameBuffer.getColorBufferTexture()
我尝试从 FrameBuffer 绑定纹理
mFilterBuffer.getColorBufferTexture().bind();
对于第一次迭代,一切都很好。但是当我尝试在 FrameBuffer 中使用他的 ColorBufferTexture 类似纹理时,我有全黑的纹理。代码:
public void process(MySprite psObject, float startX, float startY,
float endX, float endY, int mWidth, int mHeight) {
boolean frst = false;
if(psObject.getFrameBuffer() == null){
psObject.setFrameBuffer(new FrameBuffer(Pixmap.Format.RGBA8888, psObject.getTexture().getWidth(), psObject.getTexture().getHeight(), true));
}
if(pSprite == null || pSprite != psObject){
mFrameBuffer = psObject.getFrameBuffer();
frst = true;
pSprite = psObject;
}
mFrameBuffer.begin();
Gdx.gl.glViewport(0, 0, psObject.getTexture().getWidth(), psObject.getTexture().getHeight());
Gdx.graphics.getGL20().glClearColor(0f, 0f, 0f, 1f);
Gdx.graphics.getGL20().glClear(GL20.GL_COLOR_BUFFER_BIT);
ShaderProgram shader = MyUtils.newInstance().getCurrentShader();
if(!shader.isCompiled()){
Log.i("ERROR", "SHERROR " + shader.getLog());
}
if(shader != null){
if(frst){
psObject.getTexture().bind();
}else{
mFrameBuffer.getColorBufferTexture().bind();
}
shader.begin();
Matrix4 matrix = new Matrix4();
matrix.setToRotation(1, 0, 0, 180);
matrix.scale(scaleSizeInFilterProcessor, scaleSizeInFilterProcessor, 1);
shader.setUniformMatrix("u_worldView", matrix);
shader.setUniformi("u_texture", 0);
float [] start = new float[]{0f,0};
float [] end = new float[]{1f,1f};
MyUtils.newInstance().getShaderData(shader, start, end, mWidth, mHeight);
psObject.getMesh().render(shader, GL20.GL_TRIANGLES);
shader.end();
}
mFrameBuffer.end();
}