Second camera that does not draw to screen? Get pixels from this camera


#1

I have a 3d Scene which is currently viewed with an ofEasyCam.

I would like to have another camera, or some way to view the scene from another perspective.
I would like this second ‘camera’ to output the pixels to an ofPixels object instead of outputting to screen.

Is this possible? I have explored using an ofFbo slightly but am unsure.


#2

Yes. You can get your scene in an fbo doing something like:

fbo.begin();
cam.begin();
// draw smth here
cam.end
fbo.end();

fbo.readToPixels(pix)); // assuming you have an `ofPixel pix` in your header file.


#3

Thanks for the response, hope you’re having a good Christmas! I’ll try this out thank you.
As a quick note if you feel like helping me more, am I able to manipulate an Fbo like a camera? For example to have the Fbo in another position than the camera in my 3D scene?


#4

Hi,
the FBO stands for Frame Buffer Object, which is usually understood as an offscreen rendering target. It is super useful in lots of ways, where usually you want to draw something not directly to the screen but somewhere you can either access its pixels, texture or keep it in between frames, without having to render again.
So for the camera you just use an ofEasyCam or ofCamera but to have this rendered into the fbo you need to call it as @edapx explained. Also, keep in mind that fbo.readToPixels(pix); is an expensive and slow operation, so avoid it as much as you can.