Scaling an fbo for preview

Hi, this seems to be a rather trivial thing, but I can’t seem to figure it out.

I have a high resolution FBO which I plan to do a screenshot of. It works fine, but I can’t see the whole image and I can’t figure out how to scale down the fbo so that I could preview it without loosing the resolution of the original fbo. So basically I’m looking to either draw a scaled version of the fbo to a screen or assign the fbo to another fbo, scale it down and draw that.

Thanks!

1 Like

Hi there!

You need to use void ofFbo::draw(float x, float y, float width, float height) or some matrix operations (1) (2).

3 Likes

Just remembered I have this global function that returns the scaled values of a given width and height, fitting the frame to the window but keeping its proportions.

ofPoint ofxFitToScreen(const int & width, const int & height, bool upScale)
{
    ofPoint returnSize;
    
    float windowRatio = (float) ofGetWidth() / ofGetHeight();
    float frameRatio = (float) width / height;
    
    if (!upScale && ofGetWidth() > width && ofGetHeight() > height)
    {
        returnSize = ofPoint(width, height);
        ofLogNotice("ofxUtils", "upScale is set to false, so no change.");
        return returnSize;
    }
    
    else
    {
        if (windowRatio > frameRatio)
        {
            returnSize.x = (int) ofGetHeight() * frameRatio;
            returnSize.y = ofGetHeight();
        }
        
        else if (windowRatio < frameRatio)
        {
            returnSize.x = ofGetWidth();
            returnSize.y = (int) ofGetWidth() / frameRatio;
        }
        
        else if (windowRatio == frameRatio)
        {
            returnSize.x = ofGetWidth();
            returnSize.y = ofGetHeight();
        }
        
        return returnSize;
    }
}
1 Like