Building for iPhone

Hello,

Judging from the forum posts, lots of people are having difficulty building box2d for iphone at the moment.

The only adjustment I've had to make so far is to rename objective c source files which reference the box2d c++ from '.m' to '.mm'

I've put a page on the box2d wiki (http://www.box2d.org/wiki/index.php?title=Building_for_IPhone), to put information about frequently encountered problems building for iphone. If you've found other problems or other perhaps have ported the test bed and you'd like to share please reply here or have a go at editing the wiki page.

cheers

Mat
Is the base for the iPhone tests the standard XCode build? Has anybody posted iPhone projects which are closer than this? I haven't seen anything, but I just wanted to make sure I'm not missing something.

Thanks,
Eric
One problem with using the standard project for the iPhone is that the b2DebugDraw rendering isn't done using vertex arrays, so there's no quick way to get stuff up and running with visuals and everything.

I suspect it would take maybe a day's work to set up a new testbed project that would work on the iPhone; any volunteers? Since it would also need extra Objective C files and stuff like that, it would probably be best to have an iPhone specific project in the Contrib directory rather than scatter the source throughout the main project.
ewjordan wrote:
One problem with using the standard project for the iPhone is that the b2DebugDraw rendering isn't done using vertex arrays, so there's no quick way to get stuff up and running with visuals and everything.

Why is this?

ewjordan wrote:
I suspect it would take maybe a day's work to set up a new testbed project that would work on the iPhone; any volunteers? Since it would also need extra Objective C files and stuff like that, it would probably be best to have an iPhone specific project in the Contrib directory rather than scatter the source throughout the main project.

While an iPhone direction would be necessary for the TestBed, I for one would prefer if any changes to the main source, stay there, using a iPhone specific preprocessor directive.

On a wider issue, perhaps we should start organising b2DebugDraw to graphics library interfaces, as this must be code that people will want to share.
BorisTheBrave wrote:
ewjordan wrote:
One problem with using the standard project for the iPhone is that the b2DebugDraw rendering isn't done using vertex arrays, so there's no quick way to get stuff up and running with visuals and everything.

Why is this?

The problem is just that there's no glVertex2f function in the OpenGL ES spec, so to draw anything on the iPhone you'd need to completely re-write the debug draw stuff. Not a huge chore, but nobody's shared the code yet (haven't done it myself, otherwise I'd commit it). Instead of directly adding vertices through calls like that, you have to create a vertex array and then "select" it with glVertexPointer, finally calling glDrawArrays to trigger the actual drawing.

We could fairly easily change this in the main code, too, and it should work fine - to my knowledge, there's no drawback, and it may actually be faster in some cases (I'm pretty sure that's why the immediate mode stuff was removed from the ES spec - the OpenGL people are moving in the direction of considering glVertex stuff to be discouraged, FWIW), not that graphics speed is any issue in the testbed...

Quote:
While an iPhone direction would be necessary for the TestBed, I for one would prefer if any changes to the main source, stay there, using a iPhone specific preprocessor directive.

That sound good to me - the relevant tests would be

#if TARGET_IPHONE_SIMULATOR
and
#if TARGET_OS_IPHONE

Though even then, there's still substantial backing code that would need to be done in Objective C (for UI setup and all that - no GLUI on the iPhone, alas!). What are your thoughts on where that code would live?
I did port the b2DebugDraw code to OpenGL|ES and other bits of the testbed too (and wrote some new code for input system/menus)

Theres a vid up at http://www.vimeo.com/777790

I'm going to try to tidy this code up and submit this month, hopefully.
In your wiki post you mention b2math.h

You can add a gcc flags to force TARGET_OS_IPHONE and tou don't have to change b2Math.h

My complète method to build on Device
1) use .mm file and not .m file when you use c/c++ code in this class (like you say in wiki)
2) chose device target, open project settings, build tab, choose all configurations in Configuration Combo, go to GCC 4.0 - Languages, and add -DTARGET_OS_IPHONE to the Other C Flags

With this method you can compile in simulator and device without change b2math.h

Original thread: https://box2d.org/forum/viewtopic.php?t=1942