FBO 3D Object with moving Camera

I can’t seem to figure out how to draw 3D objects into an FBO correctly, with an orbiting camera. I am using the newer version of OF from github, which now has ofCamera and ofFBO in the core. I know it is under development.


My Fbo is smaller than the screen size of the app. I Am moving the camera around and its is not working inside of the fbo begin() end() calls. I think that I need to set some type of set camera width and height properties.

Any help or direction would be greatly appreciated.

some sample code

  
  
cam.begin();  
	ofSetColor(255, 0, 0, 255);  
	if(bUseFbo) {  
		fbo.begin();  
		ofClear(0, 0, 0, 1);  
	}  
	if(bScale) {  
		ofPushView();  
		glScalef(.25, .25, .25);  
	}  
	  
	ofSetColor(255, 0, 0);  
	ofBox(boxLoc.x, boxLoc.y, boxLoc.z, 100);  
	  
	if(bScale) ofPopView();  
	if(bUseFbo) fbo.end();  
	cam.end();  
	  
	if(bUseFbo) {  
		ofSetColor(0, 0, 0);  
		ofRect(10, 10, fbo.getWidth(), fbo.getHeight());  
		ofSetColor(255, 255, 255, 255);  
		fbo.draw( 10, 10 );  
	}  
  

http://nickhardeman.com/labs/OF-Forum-Attach/3D-Camera-FBO.zip

Passing in a viewport in the camera begin function that had inverted the height of the fbo solved the problem. Then I draw the fbo inverted vertically to the screen. Not sure if this is the best way of doing it, but it worked for me. Sample draw function code :

  
  
   fbo.begin();  
	ofClear(0, 0, 0, 1);  
	cam.begin(ofRectangle(0, ofGetHeight()-fbo.getHeight(),   
             fbo.getWidth(), fbo.getHeight()) );  
	  
	ofSetColor(255, 0, 0);  
	ofBox(boxLoc.x, boxLoc.y, boxLoc.z, 200);  
	ofRectangle view = ofGetCurrentViewport();  
	printf("%f, %f, %f, %f\n", view.x, view.y, view.width, view.height);  
	  
	cam.end();  
	fbo.end();  
	  
	// draw the fbo //  
	ofSetColor(255, 255, 255, 255);  
	glPushMatrix();  
	glScalef(1, -1, 1);  
	fbo.draw( 0, -fbo.getHeight() );  
	glPopMatrix();  
  

1 Like