Quantcast
Viewing all articles
Browse latest Browse all 40524

Crop Fbo to bounding box

Hi, I have a drawing inside fbo, and trying to decrease fbo size by cropping to the visible parts using bounding box. I found solution: pass fbo data to pixels and then write crop algorithm, and then allocate new fbo with new size . In the following part of code I'm trying to detect the bottom intersection. But I've got a weird problem with pixels.

    int w = 4;
    int h = 4;

    fbo.allocate(w, h, GL_RGBA);
    fbo.begin();
    ofClear(0, 0);
    fbo.end();

    fbo.begin();
    ofSetColor(255, 0, 0);
    ofDrawRectangle(0, 0, 4, 2);
    fbo.end();

    pixels.allocate(w, h, GL_RGBA);

    fbo.readToPixels(pixels);

    for(auto line = pixels.getLines().end(); line != pixels.getLines().begin(); --line){
        for(auto pixel: line.getPixels()){
            cout <<  "line: " << line.getLineNum() << " color: " << pixel.getColor() << endl;
        }
    }

output:

line: 4 color: 24, 215, 83, 118
line: 4 color: 255, 127, 0, 0
line: 4 color: 173, 7, 0, 0
line: 4 color: 1, 0, 0, 0
line: 3 color: 0, 0, 0, 0
line: 3 color: 0, 0, 0, 0
line: 3 color: 0, 0, 0, 0
line: 3 color: 0, 0, 0, 0
line: 2 color: 0, 0, 0, 0
line: 2 color: 0, 0, 0, 0
line: 2 color: 0, 0, 0, 0
line: 2 color: 0, 0, 0, 0
line: 1 color: 255, 0, 0, 255
line: 1 color: 255, 0, 0, 255
line: 1 color: 255, 0, 0, 255
line: 1 color: 255, 0, 0, 255

line:1 looks fine but what is wrong with line:4, what is the random colors doing there? After rebuilding app they may have gone, but with the random chance. Maybe there is another way to crop fbo?
This solution doesn't work for me.


Viewing all articles
Browse latest Browse all 40524

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>