Libgdx - FrameBuffer渲染和FitViewport

4

我在我的项目中使用正交相机和适应视口。

在我的render()方法中,我创建了一个frameBuffer来存储游戏的实际状态,然后创建了该缓冲区的一张pixmap,最后我设置了一个新的着色器并对该帧进行后处理:

//--- render frame to buffer
screenBuffer.begin();
camera.update();
Gdx.gl.glClearColor(1, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.setProjectionMatrix(camera.combined);
batch.begin();
batch.draw(img, 0, 0);
batch.end();
stage.draw();
//--- create pixmap from that buffer
pixmap = ScreenUtils.getFrameBufferPixmap(0, 0,screenBuffer.getWidth(), screenBuffer.getHeight());
batch.flush();
screenBuffer.end();
//--- create texture from pixmap   
renderedScreenTexture = new Texture(pixmap);
//--- finally render frame with postprocess shader
camera.update();
Gdx.gl.glClearColor(1, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.setShader(monoShader);
batch.setProjectionMatrix(camera.combined);
batch.begin();
batch.draw(renderedScreenTexture, 0,0);
batch.draw(renderedScreenTexture, 0, 0, 640, 320, 0, 0, 640, 320, false, true);
batch.end();

在我的调整大小方法中,我有:

viewport.update(width, height);
camera.position.set(camera.viewportWidth / 2,camera.viewportHeight / 2, 0);

问题在于调整窗口大小后,FitViewport无法正常工作。 当我从渲染方法中删除创建frameBuffer时,FitViewport可以正常工作。 有人能告诉我我的代码或整个概念错在哪里吗?
2个回答

2

试试这个:

// the viewPort you are using
FitViewport v = viewport; 
// end your buffer with your viewPort's position and size
screenBuffer.end(v.getScreenX(),v.getScreenY(),
    v.getScreenWidth(),v.getScreenHeight());

2

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接