HaxePunk / post-process

[Deprecated] Post processing using GLSL in HaxePunk
MIT License
13 stars 3 forks source link

Game gets squished in full screen when aspect ratios don't match. #3

Closed jon914 closed 10 years ago

jon914 commented 10 years ago

Suppose that I'm building a standalone desktop game that runs in full screen. The game is built at a specific resolution and is scaled up to fit the screen as best as it can without altering the game's aspect ratio. When I apply a shader and the aspect ratio of the game vs. the screen don't match, the game mysteriously gets squished, so it's horizontally narrower than it ought to be.

For example, if I have a 2560 x 1600 screen and my game was built at 320 x 320 (for discussion's sake), the aspect ratios don't match, so the game ends up getting squished. If I set the game's native resolution to 512 x 320, no squishing happens because the aspect ratios match up perfectly.

To be clearer about my own situation, I'm not using HaxePunk but am still using this with OpenFL. Display Tree-wise, the setup goes like this:

root

root itself is added to the OpenFL stage, has higher-than-1 values for scaleX/scaleY and has an x/y position that's non-zero, so it's centered on the screen. For the 2560 x 1600, 320 x 320 example, scaleX/Y are 5.

I've tried fiddling around with the width/height values inside PostProcess.rebuild(), PostProcess.render() and PostProcess.capture() but haven't had much luck. For example, If I try to drop the width to 1600 (320 x 5), the squishing stops, but part of the game gets chopped off.

jon914 commented 10 years ago

Figured this out.

Adding a GL.viewport(0, 0, width, height) call right after GL.bindFramebuffer(GL.FRAMEBUFFER, renderTo) in PostProcess.render() seems to do the trick.