ofEnableSmoothing on iPhone

Hi, I’m relatively new to openFrameworks but I’m loving the access it allows for easier iPhone app making. I’ve been working on my project for a few month now and I’m using basic shapes and lines with the ofxiPhone. My question is if anyone has gotten the ofEnableSmoothing to work on the iPhone device, not the simulator. Any reply would be appreciated :slight_smile:

Short answer: It doesn’t really work

Long answer: It should work and probably will soon on newer devices, and you can sort of fake it yourself.

iPhone uses GLES not openGL which is very stripped down (but still powerful) version of GL that doesn’t include a lot of the overhead (translation extra functions that aren’t really necessary). There are 2 versions of GLES, GLES1 and GLES2. iPhones before the 3GS use GLES1, everything past that (iPhone 3GS/ 4, iPad) support both GLES1 and GLES2. The best thing to do with GLES to get smoothing is use an anti-aliasing shader.

Unfortunately, GLES1 doesn’t have support for shaders, and ofxIphone is currently built for GLES1. I am pretty positive it will support GLES2 very soon though (I see a lot of references to it in the newest versions on GIT) at which point throwing an anti aliasing shader on stuff shouldn’t be too tough. I don’t know if this is something that will be built into OF or not but shouldn’t really matter.

Idea #1:
What you can do to fake anti aliasing is a number of things, most of which involve drawing something twice. The first time you draw it at like 1/4 of it’s size to an FBO (frame buffer object) and then draw that FBO at 4x it’s size, so it scales up and blurs. You can then draw regularly above it and it should have some anti-aliasing, you definitely need to experiment with it though. This will probably give a really noticeable blur and more of a shadow though unless you do it with a very tiny amount of scaling.

Idea #2:
You can draw to an FBO 4x as big then draw it scaled down, this may be sharper.

Anyone else know how to do this better or have any corrections for what I said? I’m def not sure about any of this but I think this is the basics…would love to know better ways to handle this

yeah, the draw at 4x and then scale down is a pretty standard approach to this I believe.

I have yet to get FBO working on the iphone however, so you will need to wait for a 3rd person to chime in on how to get that working.

another possibility is to enable MSAA for the rendering context. Thisi will require some work inside the openframeworks-source, but should be doable. Works for iOS sdk >= 4.0

cheers,
Stephan

Thanks all and Steve especially. Sorry about replying late. I tried using FBO although things didn’t smooth out as much as I wanted them so I’ve decided to use pngs where I can. Thanks alot still :slight_smile:

I have tried a lot of thing to draw a ofLine() without pixels. I read this post and I’ve tried to apply an FBO to solve this problem but it didn’t work.

Can anyone give me an easy and working example please :smiley: ?? And why can’t I put

ofxFBOTexture myFBO;

in void testApp::setup()?

This is my code. What’s wrong? Where I have to x4 the FBO?

Thanks!!!

  
void testApp::draw(){  
  
   ofxFBOTexture myFBO;  
	myFBO.allocate(ofGetWidth() , ofGetHeight() , false);  
	myFBO.begin();  
	  
	ofEnableAlphaBlending();  
  
	ofSetColor(0, 0, 255);  
	ofSetLineWidth(3);  
	ofLine(0,0,30,300);  
  
	ofDisableAlphaBlending();  
  
	myFBO.end();  
  
	myFBO.draw(0, 0, ofGetWidth(), ofGetHeight());  
}  

MSAA looks really promising! Will look into this as well, although it seems a bit heavy performance wise

I seem to recall trying the x4 FBO and it was too slow and not as smooth as I’d hoped. I suppose it might work if you aren’t drawing too much else.

@element - Try googling “opengl glowy lines” for various techniques. Because I needed to draw a ton of lines, the only viable option I could come up with was the simplest. Draw the lines at a low alpha and clear the screen each frame with an even lower alpha fullscreen ofRect overlay.

Place ofxFBOTexture myFBO in testApp.h. Except I would always use a pointer. That way memory management is a bit easier/cleaner on focus loss etc.

If you’re just doing lines, this is a pretty cool hack that might help out as well:

http://answers.oreilly.com/topic/1669-h-…–in-ios-4/

Great link! Looks like a book worth buying.

This link looks great http://answers.oreilly.com/topic/1669-h … -in-ios-4/

But can anyone give a simple example (p.e. zip file) base on it? :slight_smile:

thanks!!!

Just FYI, the latest oF in github has MSAA enabled for ofxiPhone and it works fine and dandy (assuming your project can take the performance hit)

I download it http://answers.oreilly.com/topic/1669-h … -in-ios-4/ but I coudn’t compile iphone emptyExample. I had 71 errors try to use the simulator 4.2 and Xcode 3.2.5

I know this release need improvement but does it work for draw smooth lines? Or needs a Xcode pre-set to compile this?

I’m desperate I just want to draw smooth lines…

Thanks! :lol:

The example code from that book is here: http://examples.oreilly.com/97805968048-…-aLines.zip and works fine in the simulator and the device.

It’s not oF but you should be able to rip out the line rendering code pretty easily.

I tried to adapt this code to OF but I couldn’t :frowning:

It uses a lot of buffers that I don’t understand.

I have a similar source like Aalines example but I had got is the same problem with line smooth.

I attached my code. I’m just trying to paint smooth line. Not complicated stick figure like the example.

Thanks!!!

[Archivo comprimido.zip](http://forum.openframeworks.cc/uploads/default/994/Archivo comprimido.zip)