How to draw only a section of an FBO

Hi all,

I’m trying to figure out how I can draw part of an FBO on the screen.
Using the draw(x,y,w,h) draws the entire fbo into the specified rectangle, but how can I just draw half of the FBO in one place and the other half in an other place?

Any pointers as to how this is done?

drawSubsection can you out:

http://openframeworks.cc/documentation/gl/ofTexture.html#!show_drawSubsection

I think you can do:

myFbo.getTexture().drawSubsection(…)

1 Like

Hey Zach,

Thanks, that seems to work - kind of.
This gives the result in the first screenshot, when I change fbo.allocate to fbo.allocate(ofGetWidth(), ofGetHeight(), GL_RGB) I get the result of the second screenshot. ( as one can guess I have an ofSpherePrimitive and an ofFbo in the .h file named sphere and fbo respectively).

I don’t understand the relation between the two, especially the right-bottom corner; that and the absence of color.

//--------------------------------------------------------------
void ofApp::setup(){
    ofEnableLighting();
    sphere.set(200, 20);
    fbo.allocate(ofGetWidth(), ofGetHeight());
}

//--------------------------------------------------------------
void ofApp::draw(){
    ofTranslate(ofGetWidth()/2, ofGetHeight()/2);
    ofSetColor(250, 0, 0);
    fbo.begin();
    sphere.draw();
    fbo.end();
    fbo.getTextureReference().drawSubsection(0, 0, 100, 100, 50, 50, 150, 150);
}


are you trying to draw the sphere in the center of the fbo?

It might help to do the following to see what’s going on (clear white opaque, and then draw red lines in the fbo to see the boundaries…)

fbo.begin();
ofClear(255,255,255, 255); // clear the fbo backgorund
ofSetColor(255,0,0);
ofLine(0,0, fbo.getWidth(), fbo.getHeight());
ofLine(0,fbo.getHeight(), fbo.getWidth(), 0);
fbo.end();

also, disable lighting will help things not appear black…

It’s really just a test to try and figure out the concept of drawing to an fbo and showing just a part.

I have another program into which I want to implement this because I need to render a scene twice, with different clip planes, and have one halve of the screen show halve with one set of parameters and the other halve with other settings.

It’s a bit hard to explain but basically I need two different ‘slices’ of some geometry (the slices being done with clip planes) rendered on the same screen. In pseudocode:

fbo1.begin();
set clipplanes a;
draw stuff;
fbo1.end();

fbo2.begin();
set clipplanes b;
draw stuff;
fbo2.end();

draw fbo1 to left halve of screen
draw fbo2 to right halve of screen

BTW, your code gives me this:

ofTranslate(ofGetWidth()/2, ofGetHeight()/2);
    fbo.begin();
    ofClear(255,255,255, 255); // clear the fbo backgorund
    ofSetColor(255,0,0);
    ofLine(0,0, fbo.getWidth(), fbo.getHeight());
    ofLine(0,fbo.getHeight(), fbo.getWidth(), 0);
    fbo.end();
    fbo.draw(0,0);

No sign of the cross that should be drawn by the two lines.

try:

ofSetColor(255,255,255);
fbo.draw(0,0);

D’oh. Silly oversight indeed.
Let’s see if I get the rest working now. Thanks a great bunch!