ofFbo on iOS - Scaling and Offset Issues

I’m having some strange issues using ofFbo on the latest Master OF 007 on iOS.

To test, I’m drawing an image to the screen, with and without the FBO being created.
With no FBO, it looks like the image on the left, with the FBO running, it looks like the image on the right


#pragma once  
#include "ofMain.h"  
#include "ofxiPhone.h"  
#include "ofxiPhoneExtras.h"  
class testApp : public ofxiPhoneApp {  
	void setup();  
	void draw();  
	ofImage bg;  
	bool useFbo;  
	ofFbo* screenBuffer;  

#include "testApp.h"  
void testApp::setup(){	  
	useFbo = true;  
	if(useFbo) {  
		ofFbo::Settings settings;    
		settings.width = 1024;    
		settings.height = 768;    
		settings.internalformat = GL_RGB;    
		settings.numSamples = 0;    
		settings.useDepth = false;    
		settings.useStencil = false;  
		screenBuffer = new ofFbo();  
void testApp::draw(){  
	if(useFbo) {  
	ofSetColor(255, 255, 255);  
	bg.draw(0, 0);  
	if(useFbo) {  
		screenBuffer->draw(0, 0);  

Any ideas?

I haven’t set this up to confirm the solution, but try setting both the width and height to 1024 (power of 2) – I suspect that’s why the FBO is scaling.

The rotation is probably from this line:

You may have to rotate before you draw the FBO.

Hope that helps,

Thanks, Stephen!

setting the width and height to 1024 fixed the scaling issue. The orientation (OFXIPHONE_ORIENTATION_LANDSCAPE_RIGHT), etc. didn’t affect the drawing, so I’m not sure why the FBO is drawn the wrong way, but nevertheless - this rotation and translation fixes it:

ofTranslate(-1024, 0, 0);
screenBuffer->draw(0, 0);


I dig this thread up because I think there is still no fix.

There is definitely a problem with FBO on iOS. It almost works and should be no big deal for the guys who wrote that code. I looked at the code of ofFbo, but didn’t find anything I could do myself.

However, I made a simple example that can easily be copy-pasted into an emptyExample to test/reproduce the problem.

void testApp::draw(){  
    ofFbo::Settings settings;    
    settings.width = mouseX;    
    settings.height = mouseY;    
    settings.internalformat = GL_RGB; // GL_RGB or GL_RGBA  
    settings.numSamples = 0;    
    settings.useDepth = false;    
    settings.useStencil = false;   
    ofFbo fbo;  
    ofClear(0, 0, 0);     
    ofSetColor(255, 0, 0);  
    ofRect(0, 0, 30, 30);  
    ofSetColor(255, 255, 0);  
    ofEllipse(40, 40, 20, 20);  
    ofSetColor(255, 255, 255, 100);  
    fbo.draw(mouseX, mouseY);  

Test 1: OSX (or windows, not tested)
In OF for OSX, just paste the code below in the draw() function. Run and move the mouse, it works perfectly as it should. The mouse is not captured, but it is in the top-left corner of the dark gray rect.

See FBO_OSX.png

Test 2: iOS (portait)
Then do the same in OF for iOS. The size of the dark gray rect is correct, however, the scale of drawings (red and yellow stuff) is modified. It jumps as you change the size of the FBO by moving the mouse, probably when you reach the next power of 2 limit.

See FBO_iOS_portait.png

Test 3: iOS (landscape)
Same as test 2, but uncomment the following line in setup():

	//If you want a landscape orientation   

Now the drawing is inverted and offset as momo_the_monster also reported.

See FBO_iOS_landscape.png

As an OF user, I expect the same behavior on iOS as on OS X, in either ortientation.

I understand there may be uncomplete areas in OF and I’m ready to fix it in code before next release, or even get the last dev version from github, but I don’t have the opengl expertise (nor time to acquire it) to understand what’s happening and fixing it myself.

I hope the this code sample can help you get quickly to the point and help you find the problem and propose a fix.

Thank you.

can you try allocating the fbo with allocate(w,h,GL_RGB) instead?
I am curious if it is an issue with the fbo settings approach.

Not trying to necro this thread without a reason, honest.

This is still happening in 0.7.4, and it’s driving me batty trying to figure it out. All I know is it’s related to the orientation changes that happened in the move to 0.7x.

My app is landscape mode (forced in the build settings), retina enabled. ofGetWidth/Height is returning the wrong value - always 640 x 960 instead of 960 x 640. If I actually call iPhoneSetOrientation to one of the landscape orientations, ofGetWidth/Height returns the correct sizes but ofGetWindowWidth/Height and ofGetScreenWidth/Height still show 640x960; mI know that this is one of the things changed in 0.7x so this is where I think the problem lies.

Hey SiW,

I tested on ios (portrait + landscape) and FBO’s, widths and heights seems to be working fine (using 0074, retina enabled). One thing I noticed is you forced landscape mode in the build settings- you mean the big grey icon in the target summary? When I tested with this everything was weird and backwards. If you leave the icon as the default ‘portrait’, and only change the iPhoneSetOrientation then it should work ok.

Yeah, the problem is a multi-faceted one, which is probably why there still isn’t a definitive fix. It depends on the version of iOS you’re targeting, whether you’re using an FBO, whether you’re using UIKit elements, how you want your app to handle rotation, and so on. I really don’t think it’s appropriate to keep the oF landscape-apps-are-really-just-portrait-apps-rotated method anymore, even if you’re not making use of UIKit (directly or indirectly via Game Center etc.) because of the Notification Center. It looks pretty dumb to have your “landscape” app and have to slide in from the side to bring in notifications, and is highly likely to get a rejection from Apple.

It is however possible to cobble together something that actually works, as I finally found out yesterday :slight_smile: It involved hacking on the ofxiPhone core, as detailed in one of the other threads on orientation issues.

Ah yes, I guess this wouldn’t work if you needed to use the keyboard input for example (which would still be in portrait mode).

I would love to see an example project in the core which has all the orientation/rotation fixes included, which handles the GL view, FBO’s and UIKit elements all together. Even if it were just for the latest versions.