Multi-camera views

Hi, I’m making a game and I want to have the normal screen (What the player sees) and a Map that’s in the bottom left corner and shows an overhad view of the entire map. I have an ofCamera that works like that, but I can’t figure out how to make that one show up as like a minimap overlayed on the main camera. Any advice?

Hi,
I think you could use an ofFbo and draw everything in there from the ‘overview-camera’, in the update() function, like:

fbo.begin();
ofClear(0);
overviewCam.begin();
// draw your geometry here
overviewCam.end();
fbo.end();

And then in draw() you could draw it with your playerCam (without the ofFbo), and after that draw the ofFbo in a corner with the fbo.draw() func.
Haven’t tested it, but think it should work.

And I think it might be nice to simplify the drawings on the map, so for example:
If you want to use a complex mesh for a tree, which would look nice for the player-view, you can maybe visualize the tree as a green circle on the map. So you could have two draw()-functions per object: draw() and drawSimple() for example.
And call drawSimple() in the ofFbo in update(). (In the examples folder the ofFbo will become clear)

Hi,

I’m currently planning to update both cameras in seperate threads for some performance increase.
Could I create a thread to handle starting the fbo, then manually call the draw() function, then cleanup in the threaded function?
For example:

void ofApp::updateOverheadCamera(){
 fbo.begin();
 ofClear(0);
 overheadCam.begin();
 this->draw();
 overheadCam.end();
 fbo.end();
}

I think you can not do opengl calls outside the main thread

Damn. That’s a shame

And I think you shouldn’t call the this->draw() function in the update().
In the approach I suggested I ment you call all the objects’ draw-functions, in case your using classes and objects.
So if you have an ofMesh named box you call box.draw() in the fbo, in ofApp::update(), and then later again in the ofApp::draw() (with the viewer-cam).

In my ofApp::update() I have a copy of the draw() code, but modified so that I can draw it from the overhead camera’s perspective, all of which is between the fbo.begin() and fbo.end(). Then in my draw() I have the code to draw the objects from the player camera’s perspective, then finally I call fbo.draw(ofGetWidth()/2, ofGetHeight()/2). However nothing shows up on the screen. Any ideas?

Ok I’ve messed about with the code, and it seems as though it’s drawing it to the scene instead of onscreen. Is there any way I can just have it draw to an image and then add that image on a GUI?

Ehm, have you allocated the fbo? Otherwise maybe call ofSetColor(255) before you draw the fbo…

The fbo is being drawn, it’s being drawn in the scene instead of as a kind of HUD. Other than that it’s working fine

Not sure if I understand correctly, but are you drawing the fbo like this:

void ofApp::draw(){
cam.begin();
// draw the scene objects
cam.end();
fbo.draw(x,y);
}

This should be like an image overlay:

Ok, It’s drawing it on the screen now, but it’s drawing it differently based on the orientation of the player.
Orientation 1:


Orientation 2:
Orientation 3:
Orientation 4:

Code as follows:

In setup():

//fbo
fbo.allocate(300,300);
fbo.begin();
ofClear(0);
fbo.end();

In update():

fbo.begin();
ofClear(0);
overheadCam.begin();
ofEnableDepthTest();
ofPushMatrix();

/*
      Draw some stuff
*/

ofDisableDepthTest();
overheadCam.end();
ofPopMatrix();
fbo.end();

And finally in draw():

/*
    Player camera drawing here
*/

playerCam.end();

if(minimap){
    ofSetColor(ofColor::white);
    ofDrawRectangle(0,0,320,320);
    fbo.draw(0,0);
}


Just a quick guess: maybe this order:

overheadCam.begin();
ofPushMatrix();
ofPopMatrix();
overheadCam.end();

Nope, same thing happens

Weird. If you don’t write anything in the fbo in ofApp::update(), but only write one color to it in ofApp::setup(), like ofClear(255, 0, 0, 255);
And then call fbo.draw(0,0) in ofApp::draw(), it should be a 300x300 red square @ 0,0, right?

Same thing happens, but instead of drawing the minimap, it’s just a red square over half the screen for the same player orientations as in the screenshots above

Think I got it, you have to call disableMouseInput() on the overheadCam.
Edit: oh, even without calling it, the overheadCam stays static with the code below.
Edit 2: But then it interacts within the drawn fbo. Calling disable would be better.
In ofApp.h

    ofEasyCam overviewCam;
    ofEasyCam viewerCam;
    ofFbo fbo;

in ofApp.cpp

//--------------------------------------------------------------
void ofApp::setup(){
    fbo.allocate(300, 300, GL_RGBA);
    overviewCam.disableMouseInput();
}

//--------------------------------------------------------------
void ofApp::update(){
    fbo.begin();
    ofClear(0);
    overviewCam.begin();
    ofDrawGrid(20, 20, 20);
    overviewCam.end();
    fbo.end();
}

//--------------------------------------------------------------
void ofApp::draw(){
    viewerCam.begin();
    ofDrawGrid(20, 20, 20);
    viewerCam.end();
    fbo.draw(0, 0);
}

Thanks very much! That works flawlessly!

1 Like