Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Tetrad · Jul 01, 2010 at 08:18 PM · inputresolutionscreeniphone4

Is it possible to get Unity iPhone 1.7 to work on the iPhone 4 at full resolution?

I've made some progress on getting my unity game to try to get the game to play back at full-res on the iPhone 4.

Here's what I've done so far, in AppController.mm, change this function to this version.

OpenEAGL_UnityCallback:

int OpenEAGL_UnityCallback(UIWindow** window, int* screenWidth, int* screenHeight) { CGRect rect = [[UIScreen mainScreen] bounds];

 // Create a full-screen window
 _window = [[UIWindow alloc] initWithFrame:rect];
 EAGLView* view = [[EAGLView alloc] initWithFrame:rect];
 [_window addSubview:view];

 // Change the content size on the iPhone 4
 {
     int w = 320, h = 480;
     float ver = [[[UIDevice currentDevice] systemVersion] floatValue];
     // Can't detect screen res in pre 3.2 devices, but they are all 320x480 anyway.
     if (ver >= 3.2) 
     {
         UIScreen* mainscr = [UIScreen mainScreen];
         w = mainscr.currentMode.size.width;
         h = mainscr.currentMode.size.height;
     }
     if( w == 640 )  // this is a naive check
     {
         view.contentScaleFactor = 2.0f;
     }
 }

 CAEAGLLayer* eaglLayer = (CAEAGLLayer*)[view layer];
 _context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];

 if (!_context)
     return false;

 if (![EAGLContext setCurrentContext:_context]) {
     _context = 0;
     return false;
 }

 GLint width;
 GLint height;
 if (!CreateWindowSurface(eaglLayer, GL_RGB565_OES, GL_DEPTH_COMPONENT16_OES, NO, &_surface, width, height )) {
     return false;
 }

 glViewport(0, 0, width, height);
 [_window makeKeyAndVisible];
 [view release];

 *window = _window;
 *screenWidth = _surface.size.width;
 *screenHeight = _surface.size.height;   

 return true;

}

CreateWindowSurface

bool CreateWindowSurface(CAEAGLLayer* eaglLayer, GLuint format, GLuint depthFormat, bool retained, MyEAGLSurface* surface, GLint& width, GLint& height ) { CGSize newSize; GLuint oldRenderbuffer; GLuint oldFramebuffer;

 surface->format = format;
 surface->depthFormat = depthFormat;

 surface->depthBuffer = 0;
 surface->renderbuffer = 0;
 surface->framebuffer = 0;

 eaglLayer.opaque = YES;
 eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
                                 [NSNumber numberWithBool:FALSE], kEAGLDrawablePropertyRetainedBacking, kEAGLColorFormatRGB565, kEAGLDrawablePropertyColorFormat, nil];

 newSize = [eaglLayer bounds].size;
 newSize.width = roundf(newSize.width);
 newSize.height = roundf(newSize.height);

 glGetIntegerv(GL_RENDERBUFFER_BINDING_OES, (GLint *) &oldRenderbuffer);
 glGetIntegerv(GL_FRAMEBUFFER_BINDING_OES, (GLint *) &oldFramebuffer);

 glGenRenderbuffersOES(1, &surface->renderbuffer);
 glBindRenderbufferOES(GL_RENDERBUFFER_OES, surface->renderbuffer);

 if(![_context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:eaglLayer]) {
     glDeleteRenderbuffersOES(1, &surface->renderbuffer);
     glBindRenderbufferOES(GL_RENDERBUFFER_BINDING_OES, oldRenderbuffer);
     return false;
 }

 // Get the renderbuffer size.
 glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &width);
 glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &height);
 newSize.width = width;
 newSize.height = height;

 NSLog( @"\n\nwidth = %d, height = %d\n\n\n", width, height );

 glGenFramebuffersOES(1, &surface->framebuffer);
 glBindFramebufferOES(GL_FRAMEBUFFER_OES, surface->framebuffer);
 glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, surface->renderbuffer);
 if (depthFormat) {
     glGenRenderbuffersOES(1, &surface->depthBuffer);
     glBindRenderbufferOES(GL_RENDERBUFFER_OES, surface->depthBuffer);
     glRenderbufferStorageOES(GL_RENDERBUFFER_OES, surface->depthFormat, newSize.width, newSize.height);
     glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, surface->depthBuffer);
 }

 surface->size = newSize;
 glBindRenderbufferOES(GL_RENDERBUFFER_OES, oldRenderbuffer);

 CHECK_GL_ERROR();

 return true;

}

Now this works great for rendering, at least in my preliminary tests. The problem I'm running into is that my Input seems to be broken. Inside Unity, it reports the Screen.width and Screen.height to be 960x640 (correctly). But, say, if I test Input.mousePosition in the upper right corner of the screen it reports (480, 320). At least in one direction. If I rotate the phone to landscape right, it reports the upper right to be (960, 640), but the lower left to be (480, 320). This causes issues when I try to do input with ScreenPointToRay. I'm sure I could work around it, but it would be a complete hack with scaling variables depending on the resolution and orientation of the device. I'll admit I haven't tried using the iPhoneInput class and checking touches yet.

Has anybody gotten input to work on the iPhone 4 at full res?

Edit: copy/pasted code I'm actually using.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image franktinsley · Jul 14, 2010 at 05:29 AM 0
Share

It's strange. I got this to work with the FPS Unity demo project but when I try it with my own project I keep getting an error in xcode t line 508 on view.contentScaleFactor = 2.0f; saying error: request for member 'contentScaleFactor' in 'view', which is of non-class type 'EAGLView*' Any ideas on what I'm doing wrong?

avatar image Tetrad · Jul 14, 2010 at 06:11 AM 0
Share

You'll probably need to set your Base SD$$anonymous$$ to 4.0.

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Tetrad · Jul 08, 2010 at 08:16 PM

Well I managed to hack around the input bugs. With the "render at full res" code in the question, I use this class as a wrapper to Input.mousePosition:

public static class Inputx { #if UNITY_IPHONE static Vector2 lastKnownCursorPosition = Vector2.zero; static bool isIphone4 = false; #endif

 public static Vector2 cursorPosition
 {
     get
     {

if UNITY_IPHONE

        lastKnownCursorPosition = Input.mousePosition;

         if( !isIphone4 && ( Screen.width == 960 && Screen.height == 640 ) )  // iPhone 4 gate
         {
             isIphone4 = true;
         }

         if( isIphone4 )
         {
             if( iPhoneSettings.screenOrientation == iPhoneScreenOrientation.LandscapeLeft || iPhoneSettings.screenOrientation == iPhoneScreenOrientation.Portrait )
             {
                 lastKnownCursorPosition *= 2.0f;
             }
             else if( iPhoneSettings.screenOrientation == iPhoneScreenOrientation.LandscapeRight || iPhoneSettings.screenOrientation == iPhoneScreenOrientation.PortraitUpsideDown )
             {
                 lastKnownCursorPosition -= new Vector2( 480, 320 );
                 lastKnownCursorPosition *= 2.0f;
             }
         }

         return lastKnownCursorPosition;

else

        return Input.mousePosition;

endif

    }
 }

}

I'm sure similar logic could be used to adjust touch positions.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image jimbobuk · Jul 17, 2010 at 03:30 PM 0
Share

I'm going to have a go at using something similar as this right now. I can confirm that this touch input position is a problem with Unity 3 which natively supports the iPhone 4 and "just works" out of the box. Sadly it seems the touches are similarly mapped as you experienced.

avatar image
1

Answer by Dimitris 1 · Sep 07, 2010 at 05:17 PM

To fix touch input you can use another "hack" as well, which will also work with Unity GUI objects and it does not require any more code in Unity. Just update the methods in Cocoa that forward the touch events to Unity like this (obviously you should change that hardcoded 2 I have there to 1 if the device is not HD and also make sure you change and forward all touches, not just the 1st one as I do in this example):

- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
    //scale the touch objects
    UITouch *touch = [[touches allObjects] objectAtIndex:0];
    NSLog(@"touch = %@", touch);
    [touch setValue:[NSValue valueWithCGPoint:CGPointMake([touch locationInView:self].x * 2, [touch locationInView:self].y * 2)] forKey:@"locationInWindow"];
    UnitySendTouchesBegin([NSSet setWithObject:touch], event);
}

Should I also mention that your app is likely to crash on new OS versions? :)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Tore · Sep 02, 2010 at 03:03 PM

Where do you put the "class as a wrapper to Input.mousePosition" ? xCode or Unity?

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bentford · Sep 04, 2010 at 09:49 AM 0
Share

This should be a comment, not an answer.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

How to make my game fit into my droid? 1 Answer

Scale GUITexture to screen resolutions 1 Answer

Fitting Into Different Screens 0 Answers

Can I customize the resolution window that appears at the start of my executable? 2 Answers

iPhone Resolution Screen Switch 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges