iPad Working

Hey so, I’m currently working on a project that is great for the iPad and I have everything up and running with OF/iPad (at least in the emulator) so I thought I’d give a quick rundown of a few changes I needed to make and some obvious issues that arise.

First and foremost I tried using 3.2 SDK Beta 2 and it was a huge mess/nightmare, broke OF for working from iPhone in device mode and I uninstalled it.

Now I installed 3.2 SDK Beta 5 and it works fine with everything. At first I thought I could just target the iPad in the Target settings and everything would be cake, and it seemed to work fine. Then I started using some OF Images and they looked crazy huge! Thought something was messed up then I realized that basically everything was scaling up to 1024x768 vs the iPhone 480x320 (I’m working in landscape obviously…)

So I really don’t know a lot about the backend of ofxIPhone but I figured what was happening was that the dimensions were hard coded into GL or something and stuck. So I changed the dimensions in ofAppiPhoneWindow.mm timerLoop function and everything worked. This is obviously SUPER sloppy and terrible, so I stepped it up a bit and followed the structure setup already and added two constants to ofxIphoneExtras.h

  
  
//Screen Resolutions (Iphone/ipod touch or iPad)  
#define OFXIPHONE_RESOLUTION_IPHONE 0  
#define OFXIPHONE_RESOLUTION_IPAD	1  

then I went into ofAppiPhoneWindow.h and added a function and a var,

  
  
public:  
void setResolution(int resolution);  
  
protected:  
int resolution;  
  

and setup the function in ofAppiPhoneWindow.mm under the window property functions

  
  
void ofAppiPhoneWindow::setResolution(int resolution) {  
	switch (resolution) {  
		case OFXIPHONE_RESOLUTION_IPHONE:  
			this->resolution = OFXIPHONE_RESOLUTION_IPHONE;  
			break;  
		case OFXIPHONE_RESOLUTION_IPAD:  
			this->resolution = OFXIPHONE_RESOLUTION_IPAD;  
			break;  
		default:  
			break;  
	}  
}  
  

then changed the timer loop under if(bEnableSetupScreen) to the following code replacing the w & h settings

  
  
int w, h;  
		  
if(resolution == OFXIPHONE_RESOLUTION_IPHONE) {  
	w = 320;  
	h = 420;  
} else {  
	w = 768;  
	h = 1024;  
}  
  

so the final step was just putting a function into ofxiPhoneExtras.mm to talk to the window in a clean way, first in ofxiPhoneExtras.h

  
  
//Set Resolution for iphone or ipad  
void iPhoneSetResolution(int resolution);  
  

then in ofxiPhoneExtras.mm

  
  
//--------------------------------------------------------------  
void iPhoneSetResolution(int resolution) {  
	iPhoneGetOFWindow()->setResolution(resolution);  
}  
  

Hope this makes sense, I can also put up the actual files but I wanted to see if anyone had any suggestions for maybe doing this in a better way? I also set it to default to iPhone resolution so basically if oyu wanna target iPad you use this otherwise you just ignore it.

Also I’m using Memo’s build from GitHub which uses Poco and .61 structure and everything…so I think its one of the newest builds.

Also I haven’t experiment much beyond just showing an image at the rihgt size, so can anyone tell me if what I’m doing is terrible and will mess up something else really bad? :slight_smile:

Thanks,
-Steve

Hi Steve, thanks for pointing this out. There should be no direct references to the iphone resolution of 320x480 in ofxiPhone, I don’t know how that one got in there :P. All other occasions where we need the dimensions, read the size directly from the window ( [[[UIApplication sharedApplication] keyWindow] bounds].size ) which is created fullscreen as per the Apple HIG ( [[UIScreen mainScreen] bounds].size )

The solution is quite simple. I think all that needs to be done is to replace 320 and 480 by window width and height:

  
CGSize s = [[[UIApplication sharedApplication] keyWindow] bounds].size;  
w = s.width;  
h = s.height;  

note I’m not using ofGetWidth() or ofGetHeight() because they return rotated values if you have switched to working in landscape mode, whereas for here we need the un-rotated raw values.

This will be in the next ofxiphone release which is coming very shortly…

Ahhhh man thats so much easier :slight_smile: I figured something like this might work but I thought the opposite was happening, that you were setting s.width and s.height. Makes sense now

Thanks for the fix and can’t wait to see the new version!

-Steve

hey by the way, I haven’t tested that code, so best check it to make sure that it works!! If you notice any other weirdnesses on iPad let us know so we can get fixes in the next update…

Thanks just tried it out and it works perfect, nice and easy fix.

Hey guys. Do you have any instructions up for getting the 3.2 SDK working nicely with the ofxiPhone examples?

I recently did the update so I can start porting over some non-OF related projects to iPad, and am now having trouble compiling any ofxiPhone related projects (seems that the paths to the frameworks changed).

Any tips would be appreciated!
Jeff

What kind of issues are you having? The first or second beta did not work for me at all, but the newest one (I believe it is 5) works great with no issues.

Before I was getting a crazy amount of errors, mostly related to something called Bits.cpp or something like that, linking library issues. I never really looked into it because at the time I had to get some stuff working on the iphone so just uninstalled the beta and installed the regular SDK.

I figured I’d try to fix it since I had some time but when i downloaded the latest beta everything just worked.

-Steve

Hi

Thanks again for ofxiPhone! :smiley: works great! For the iPad simulator on SDK 3.2 I just upgraded the Target for iPad as in the Apple Doc recommended. Most ofxiPhone examples just use now the 1024*768 screen. iPhoneGuiExample stays in the iPhone format, why?

greetings ascorbin
[attachment=0:6mg8l3ou]ipad_upgrade.png[/attachment:6mg8l3ou]

Appears xCode has some new bugs related to this “Upgrade to iPad” feature.

Well, I found the issue. Weirdest thing, after splitting the target to iPad (rather than universal binary, I have two targets and executables), the Library Search paths of the iPad version are all escaped slashed for the surrounding quotes. After manually removing all the backslashes, it compiles fine.

Annoying, but at least I have my answer. Looking forward to seeing what fun things the openFrameworks community does with this new screen real-estate!

@grayfuse
That sounds strange, I haven’t tried the non-universal approach so can’t comment.

@ascorbin
Anything that uses the iphone SDK for gui stuff will need extra code to get it to work and check whether the device is running on iphone or ipad. That example uses a nib (interface builder file, actually the extension is xib, but same thing). That nib is set to be 320x480, and all the controls are laid out in absolute positions. To make a universal binary you’d need to create another nib at 768x1024, lay out the controls the way you want them, then from the app check if the device is iphone or ipad, then load the appropriate nib.
If you aren’t using a nib, then your life is a bit simpler. Just make sure you never position or size an object absolutely, but always make it relative to ofGetWidth or ofGetHeight (this goes for speed and acceleration etc. of objects too. One thing I usually do is:

#define kScalerX ofGetWidth()/320
#define kScalerY ofGetHeight()/480

then whereever you have positioned, or sized, or incremented the positions or size (i.e. speed) of an object, just multiply the number by kScalerX or kScalerY

I had my app working on the iPhone and have since upgraded to the 3.2b5 sdk. I compiled to iPhone and it works OK. I then set it to create a Universal app. All my code uses screen width and height to scale. The app works on the iPhone, simulator or device, but if I try running on the iPad, my app runs at what looks like double resolution. I only see the top left part of the screen. I have a debug to show my screen width and height are iPad size, but the simulator seems to be drawing zoomed up.

I must be missing something but can’t see what it is…any ideas?

When I tried to use a demo app on the iPad, fontShapesExample, doing the same - setting to Universal. It came out as an iPhone size app and gave the 1x, 2x zoom out/in button when run on the iPad simulator. My app didn’t get this…

Aah, just read memo’s entry above a few times more…! When I added the lines into ofAppiPhoneWindow.mm at ofAppiPhoneWindow::timerLoop() replacing the 480, 320 lines, it all worked fine. Why didn’t I do that the other day!

  
  
CGSize s = [[[UIApplication sharedApplication] keyWindow] bounds].size;  
w = s.width;  
h = s.height;  
  

Thanks

Hmm, using 3.2 I’m having a similar problem as happyt. It looks like that code is already in my TimerLoop(), but even on a fresh download of of iPhone 0061 it gives me the pixel double version with a Universal or iPad Only binary. Not sure whats wrong, and any help is appreciated :stuck_out_tongue:

I would stay away from Apple’s “Upgrade target for ipad…” stuff. I have tried that out and it causes a number of issues with library linking that is a pain to change back. What I would do is simply go into the existing target build settings and set the target device to iPad. This will cause it to compile for ipad and if you have also changed the width/height issue you should have no problems and be fine :slight_smile:

-Steve

maybe one lazy way of scaling everything up for the ipad is popping a transform matrix onto the front of your draw()
that way, all draw commands exist in the transformed space and you can keep all your other code the same whilst hiking the resolution.
i get that in most situations, you’re going to actually want to do something with that extra resolution other than have smoother graphics. just a thought though

i havent had any problems building to the ipad. very smooth workflow in getting the examples to compile.

i think to get the gui example i had to edit the xib view to 768 x 1040 and change the file owners class to the view controller.

in regardes to the gui example it seems when your using a UIView the multi-touch events don’t seem to work. or at least thats what the comment’s say. of course i didn’t listen and tried to anyways. ;( the ofx multi-touch is much easier to work with than apples methods. so i was just thinking if it would be possible to to just forward the touch set from the gui view down the responder chain with .nextResponder.nextResponder so the events will come into the ofWindow ?

now that compiling ofx iphone is breeze im really enjoying of. im thinking why i never used it much before.

so how i convert from iphone to ipad or to ipad/iphone universal is…

  1. got to get info on project then to build tab and set to all configurations then set sdk to 3.2. device.
    2.go to target get info then to build tab and set to all configurations then set sdk to 3.2 device.
    3.scroll down and change the family target from iphone to ipad.
    3.go back to get info on the project then to build tab set sdk to 3.2 device and scroll down and set the target family to ipad. then change all configurations to debug and back to all again to make sure the settings take effect.
    4.change .plist
    5.build debug
    6.device arm7

i havent had any problems building to the ipad. very smooth workflow in getting the examples to compile.

i think to get the gui example i had to edit the xib view to 768 x 1040 and change the file owners class to the view controller.

in regardes to the gui example it seems when your using a UIView the multi-touch events don’t seem to work. or at least thats what the comment’s say. of course i didn’t listen and tried to anyways. ;( the ofx multi-touch is much easier to work with than apples methods. so i was just thinking if it would be possible to to just forward the touch set from the gui view down the responder chain with .nextResponder.nextResponder so the events will come into the ofWindow ?

now that compiling ofx iphone is breeze im really enjoying of. im thinking why i never used it much before.

so how i convert from iphone to ipad or to ipad/iphone universal is…

  1. got to get info on project then to build tab and set to all configurations then set sdk to 3.2. device.
    2.go to target get info then to build tab and set to all configurations then set sdk to 3.2 device.
    3.scroll down and change the family target from iphone to ipad.
    3.go back to get info on the project then to build tab set sdk to 3.2 device and scroll down and set the target family to ipad. then change all configurations to debug and back to all again to make sure the settings take effect.
    4.change .plist
    5.build debug
    6.device arm7

It looks like that code is already in my TimerLoop(), but even on a fresh download of of iPhone 0061 it gives me the pixel double version with a Universal or iPad Only binary. Not sure whats wrong, and any help is appreciated :stuck_out_tongue: