Question about FBO and viewport / world bounds

So I’m still trying to get the hang of frame buffer objects and the one thing I still don’t quite understand is the world points in reference to the FBO.

So assuming I’m in a 2D environment and there’s objects drawn behind the FBO (not in FBO) and object above FBO (draw inside FBO), how do I deal with the world bounds when the FBO looking off screen? So basically I’m using FBO similar to photo-shop with layers.

So lets say the “camera” is looking into the world with bounds
(-2,-2) to (2,2) and the FBO has the bounds (1,-1) to (3,1). Drawing is easy as you just treat it as a texture, but my problem stems from drawing to the buffer, especialy since the objects above draw function behaves the same way regardless of what’s below. So what do I need to put in the blank sections in the below code.

void layer::drawToBuffer()
{
   glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, mFBO);

   //how do I setup the bounds, viewport, etc?

   //how do I clear the buffer?

   drawAbove();

   //how do I restore the original world bounds and other values.

   glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
}

I’m not sure you understand what an FBO is. It’s not an object in the world. It’s not a “thing” that can be in front of or behind something. There are no “layers”. The FBO has no “bounds” (not in the sense that you mean).

An FBO is just a collection of images that you can render to.

As with any rendering, you must set up the viewport for the size of image you’re rendering into. This of course uses glViewport.

FBOs are cleared just like any image (similarly, you don’t render into them any differently): with glClear.

I’m aware it’s just something to render to, what I meant to say is I want to use it in such a way that it acts like a layer so I can just call draw to everything above it once so I can just draw that “layer” anytime I need to redraw.

What I wasn’t sure about was what represents the limits of FBO and if glViewPort was explicitly for the actual screen area or not. So if I understood what you just said, those calls that normally apply to the actual render area still applies for the FBO and there’s no special call for FBOs when it comes to the viewing area of the FBO.

Thanks