Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Libgdx - FrameBuffer rendering and FitViewport

I use ortho camera and FitViewport at my project.

In my render() method i create a fremeBuffer to store actual state of my game, then create a pixmap of that buffer and finally i set a new shader and do my postprocess stuff with that frame:

//--- 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();

At my resize method I have:

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

The problem is that after resizing a window FitViewport doesen't work. When i remove a creating frameBuffer from render method FitViewport works fine. Can anybody tell me what is wrong with my code or whole concept?

like image 697
user3107190 Avatar asked Sep 12 '25 21:09

user3107190


1 Answers

You may have to call fitViewport.apply() before drawing your frameBuffer.

like image 130
Sebastian Avatar answered Sep 16 '25 08:09

Sebastian