Failing Screen Resize Method
Posted
by
StrongJoshua
on Game Development
See other posts from Game Development
or by StrongJoshua
Published on 2014-06-13T02:36:40Z
Indexed on
2014/06/13
3:42 UTC
Read the original article
Hit count: 236
So I want my game to draw to a specific "optimal" size and then be stretched to fit screens that are a different size. I'm using LibGDX and figured that I could just draw everything to a FrameBuffer and then resize that buffer to the appropriate size when drawing it to the actual display. However, my method does not work, it just results in a black screen with the top right quarter of the screen white.
Intermediary is the FBO, interMatrix is a Matrix4 object, and camera is an OrthographicCamera.
@Override
public void render()
{
// update actors
currentStage.act();
//render to intermediary buffer
batch.setProjectionMatrix(interMatrix);
intermediary.begin();
batch.begin();
currentStage.draw();
batch.flush();
intermediary.end();
//resize to actual width and height
Sprite s = new Sprite(intermediary.getColorBufferTexture());
s.flip(true, false);
batch.setProjectionMatrix(camera.combined);
batch.draw(s.getTexture(), 0, 0, width, height);
batch.end();
}
These are the constructors for the above mentioned objects (GAME_WIDTH and HEIGHT are the "optimal" settings, width and height are the actual sizes, which are the same when running on desktop). intermediary = new FrameBuffer(Format.RGBA8888, GAME_WIDTH, GAME_HEIGHT, false);
interMatrix = new Matrix4();
camera = new OrthographicCamera(width, height);
interMatrix.setToOrtho2D(0, 0, GAME_WIDTH, GAME_HEIGHT);
Is there a better way of doing this or can is this a viable option and how do I fix what I have?
© Game Development or respective owner