Window resizing and aspect ratio


Does OF have a function to maintain window aspect ratio on window resize?


In your ofApp::windowResized(newW, newH) method, just use ofSetWindowShape(w, h). Where:

// preserve Width
w = newW;
h = w / desiredAspect; 

// preserve Height
h = newH;
w = h * desiredAspect;

Yeah I figured out that there is no OF function implemented. So i Implemented it myself just the way you proposed.


@grega_pusnik Did this work nicely for you? I’m on windows, and when I’ve tried this sort of thing in the past, the result is a little buggy. (Buggy in that the window will be the right aspect ratio but will momentarily flash to a different size that is outside of the defined aspect ratio.)

I’m also having troubles with flashes, but in the same aspect ratio. I’ll let you know if I fix it.

1 Like