iphone retina display support

Hi,
I just tried out orx on an iphone4 and noticed that it was using a resolution of 320x480 instead of the native resolution of 640x960.
this means the game will scale everything down and then it will be scaled up again. long story short: everything looks horribly pixelish.

first of all there was a bug in setting the contentScaleFactor:
--- plugins/Display/iPhone/orxDisplay.m
+++ plugins/Display/iPhone/orxDisplay.m
@@ -292,8 +292,8 @@
                                     [NSNumber numberWithBool:NO], kEAGLDrawablePropertyRetainedBacking, kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil];
 
     /* Sets scale factor */
-    self.contentScaleFactor = (([UIScreen respondsToSelector:@selector(scale)] != NO)
-                            && ([UIScreen mainScreen].scale == 2.0f))
+    self.contentScaleFactor = (([none[UIScreen mainScreen] respondsToSelector:@selector(scale)] != NO)
+                            && ( [UIScreen mainScreen].scale == 2.0f))
                             ? 2.0f
                             : 1.0f;
so UIScreen will never respond to the selector scale and therefore the high resolution will never be used. [UIScreen mainScreen] should be checked for that selector instead.

After that all the touch events will report wrong coordinates as those also have to be multiplied by this contentScaleFactor.

in the following I'll paste the diffs of the changes required to make the retina display to work with orx.
--- plugins/Display/iPhone/orxDisplay.m
+++ plugins/Display/iPhone/orxDisplay.m



/* Inits event's payload */
orxMemory_Zero(&stPayload, sizeof(orxSYSTEM_EVENT_PAYLOAD));
- stPayload.poUIEvent = _poEvent;
- stPayload.poTouchList = _poTouchList;
+ stPayload.poUIEvent = _poEvent;
+ stPayload.poTouchList = _poTouchList;
+ stPayload.fContentScaleFactor = self.contentScaleFactor;

/* Sends it */
orxEVENT_SEND(orxEVENT_TYPE_SYSTEM, orxSYSTEM_EVENT_TOUCH_BEGIN, self, orxNULL, &stPayload);


/* Inits event's payload */
orxMemory_Zero(&stPayload, sizeof(orxSYSTEM_EVENT_PAYLOAD));
- stPayload.poUIEvent = _poEvent;
- stPayload.poTouchList = _poTouchList;
+ stPayload.poUIEvent = _poEvent;
+ stPayload.poTouchList = _poTouchList;
+ stPayload.fContentScaleFactor = self.contentScaleFactor;

/* Sends it */
orxEVENT_SEND(orxEVENT_TYPE_SYSTEM, orxSYSTEM_EVENT_TOUCH_MOVE, self, orxNULL, &stPayload);


/* Inits event's payload */
orxMemory_Zero(&stPayload, sizeof(orxSYSTEM_EVENT_PAYLOAD));
- stPayload.poUIEvent = _poEvent;
- stPayload.poTouchList = _poTouchList;
+ stPayload.poUIEvent = _poEvent;
+ stPayload.poTouchList = _poTouchList;
+ stPayload.fContentScaleFactor = self.contentScaleFactor;

/* Sends it */
orxEVENT_SEND(orxEVENT_TYPE_SYSTEM, orxSYSTEM_EVENT_TOUCH_END, self, orxNULL, &stPayload);


/* Inits event's payload */
orxMemory_Zero(&stPayload, sizeof(orxSYSTEM_EVENT_PAYLOAD));
- stPayload.poUIEvent = _poEvent;
- stPayload.poTouchList = _poTouchList;
+ stPayload.poUIEvent = _poEvent;
+ stPayload.poTouchList = _poTouchList;
+ stPayload.fContentScaleFactor = self.contentScaleFactor;

/* Sends end event */
orxEVENT_SEND(orxEVENT_TYPE_SYSTEM, orxSYSTEM_EVENT_TOUCH_END, self, orxNULL, &stPayload);
--- include/core/orxSystem.h
+++ include/core/orxSystem.h	
@@ -102,6 +102,8 @@
         /* Motion event */
         UIEventSubtype  eMotion;
       };
+      
+      orxFLOAT fContentScaleFactor;
     };
 
     /* Accelerate event */

--- plugins/Mouse/iPhone/orxMouse.m	
+++ plugins/Mouse/iPhone/orxMouse.m
@@ -98,9 +98,12 @@
 
       /* Gets its position inside view */
       vViewPosition = [poTouch locationInView:(orxView *)_pstEvent->hSender];
-
+      
       /* Gets new position */
-      orxVector_Set(&vNewPosition, orx2F(vViewPosition.x), orx2F(vViewPosition.y), orxFLOAT_0);
+      orxVector_Set(&vNewPosition,
+                    orx2F(vViewPosition.x * pstPayload->fContentScaleFactor),
+                    orx2F(pstPayload->fContentScaleFactor * vViewPosition.y),
+                    orxFLOAT_0);
 
       /* Updates mouse move */
       orxVector_Sub(&(sstMouse.vMouseMove), &(sstMouse.vMouseMove), &(sstMouse.vMousePosition));

note: my version of orx is a bit outdated, so the line numbers might not match.

Comments

  • edited October 2011
    Hi!

    By a little outdated you probably mean more than 2 months as I fixed the retina display in August with a similar fix. ;)

    However the touch coordinates eluded me (I was probably just looking at how ugly orx's profiler looked on retina display and was happy when it got fixed and stopped there), so I'll apply your patch for that tonight.

    Thanks!
Sign In or Register to comment.