Enable / disable anti-aliasing while app is running?

Hey guys,

I’m using window->enableAntiAliasing(4) on initialization an application in iOS. I’ve found an issue when antialiasing is enabled, the screen flickers on rotation. Is there a way I can enable and disable the antiAliasing settings while the app is running?

Or, is there a way I can reference ofAppiPhoneWindow from the application?

Thanks,
Steve

  
	  
ofAppiPhoneWindow * window = new ofAppiPhoneWindow();  
window->enableDepthBuffer();  
window->enableAntiAliasing(4);    
  

I could be wrong, but I don’t think you can. The ES2Renderer only has the antialiasing set when it’s allocated and I don’t see anything online that indicates you can set it anywhere else.

i don’t know iOS development, but what i would do is set up two FBOs – one with antialiasing and one without (assuming you can do antialiased FBOs on iOS). then you can switch which one you’re drawing into.

I also imagine it’s probably better to try to find the source of the flickering rather than hack a solution. When I get a chance, I can see if I have the same issue on rotation and by rotation do you mean orientation change?

Hey guys,

Thanks for the responses –

Josh, yes I read on an OpenGL forum somewhere supporting this, that the full screen anti-aliasing can only be set when the app renderer initializes.

Kyle, two FBOs were my thoughts, too – the only issue is multisampling (anti aliasing) isn’t supported in ofFBO in iOS. I haven’t found a way around this…

Seth – yes, the flicker happens in the app on orientation change, when I have gui layer added, like this:
[ofxiPhoneGetGLView() addSubview: guiViewController.view];

and anti-aliasing enabled in main.mm:
window->enableAntiAliasing(4);

Removing either the antialiasing or the gui subview resolves the flickering problem.

This issue can easily be replicated in the bundled iPhoneGuiExample, by:

  1. enabling antialiasing in main.mm:
  
  
int main(){  
	ofAppiPhoneWindow * window = new ofAppiPhoneWindow();  
    window->enableAntiAliasing(4);    
	ofSetupOpenGL(window, 1024,768, OF_FULLSCREEN);	  
    ofRunApp(new testApp);  
}  
  

  1. Adding this function to myGuiView.mm to make the layer rotate:
  
  
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {  
	return YES;  
}  
  

  1. And adding the subview to ofxiPhoneGetGLView() instead of ofxiPhoneGetUIWindow() to allow testApp to receive touch events:

testApp.mm, line 21. change:

  
  
[ofxiPhoneGetGLView() addSubview:myGuiViewController.view];  
to:  
[ofxiPhoneGetGLView() addSubview:myGuiViewController.view];  
  

Any leads on how I can enable anti-aliasing and remove the app flicker on orientation change is really appreciated!

Thanks,
Steve

I’m curious if you don’t use shouldAutorotateToInterfaceOrientation and inside deviceOrientationChanged event in testApp you manually rotate the view if the same thing occurs.

Something like:

  
//--------------------------------------------------------------  
void testApp::deviceOrientationChanged(int newOrientation){  
	  
	if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {  
		  
//5 is flat  
		if (newOrientation != 5) {  
			  
			//transform opengl ??  
			ofxiPhoneSetOrientation((UIDeviceOrientation) newOrientation);  
			  
//animate GUI orientation change  
			[UIView beginAnimations:nil context:NULL];  
			[UIView setAnimationDuration:0.5];  
			[UIView setAnimationCurve:UIViewAnimationCurveLinear];  
			[UIView setAnimationBeginsFromCurrentState:YES];  
			  
			//transform the gui  
			switch (newOrientation) {  
				case OFXIPHONE_ORIENTATION_PORTRAIT:  
					myIpadController.view.transform = CGAffineTransformMakeRotation(0);  
					myIpadController.view.center = CGPointMake(300/2, 1024 - 450/2); //x/y  
					myIpadController.view.bounds = CGRectMake(0, 0, 300, 450);  
					break;				  
				case OFXIPHONE_ORIENTATION_UPSIDEDOWN:  
					myIpadController.view.transform = CGAffineTransformMakeRotation(PI );  
					myIpadController.view.center = CGPointMake(768 - 300/2, 450/2); // x/y  
					myIpadController.view.bounds = CGRectMake(0, 0, 300, 450);  
					break;  
				case OFXIPHONE_ORIENTATION_LANDSCAPE_LEFT:  
					myIpadController.view.transform = CGAffineTransformMakeRotation(-PI/2);  
					myIpadController.view.center = CGPointMake(768 - 450/2, 1024 - 300/2); //y / x	  
					myIpadController.view.bounds = CGRectMake(0, 0, 300, 450);  
					break;  
				case OFXIPHONE_ORIENTATION_LANDSCAPE_RIGHT:  
					myIpadController.view.transform = CGAffineTransformMakeRotation(PI/2); // y / x  
					myIpadController.view.center = CGPointMake(450/2, 300/2);  
					myIpadController.view.bounds = CGRectMake(0, 0, 300, 450);  
					break;  
			}  
			  
			[UIView commitAnimations];  
		}	  
	}  
}  

Hey Seth,

This is a good lead…

The code below works – I can control the rotation from testApp, but the app still flickers – it’s happening on view.transform with anti-aliasing on and the UIView added as a sublayer to ofxiPhoneGetGLView()

Any other thoughts? I’ll update this post if I find a solution…

Thanks!
Steve

I know it’s not ideal, but if you don’t need the animation, you can just set the rotation and have it jump to it. I’m curious if it flickers during that or not.

I’m also curious if this could be do to the openGL not fully on it’s own thread (I think). When the uikit is processing heavy stuff (like rotating) it can pause the openGL loop. I’ve been meaning to try to get openGL entirely on it’s own thread, but without much luck. Although, when i’ve seen it pause before, it wouldn’t flickr - it’d just stop updating.