I am currently in the process of testing an OpenGL ES app with iPhone 4. I developed the app initially on an iPhone 3G and in the 3G simulator, using this project as a starting point rather than apple's, which I couldn't understand. I see now that this may have been a mistake.
When I tried to play the game on the iPhone 4, the touch events are giving a high-resolution output (ie x from 0-639, y from 0-959) rather than the low res touch points that my game needs (that is, x:0-319, y:0-479). I have looked at several apple example projects such as GLPaint, and this only seems to give low res touch points, but I can't see what the difference is between that project and mine.
Any help anyone can give would be much apprecia开发者_Go百科ted, this is for a project that is due in a few days' time! (I know, how could I not test it on iPhone 4 or even the simulator! But, you live, you learn...)
As has happened every time I have posted something on SO, I figured out the answer shortly afterwards, so I am posting it in case someone as skittish and worrisome as me runs into this problem.
I was passing the touch information from my GLView to the GLViewController I had defined, and this was dealing with the touch information. It was making a CGPoint for each touch, by getting a touch point using this message to the UITouch object:
CGPoint touchPoint = [touch locationInView:self.view];
The problem seems to be that the GLViewController was getting the location of the touch in a UIView object, not a GLView subclassing of this object. So, assuming glView is a property of type GLView of GLViewController, if you change the code to
CGPoint touchPoint = [touch locationInView:self.glView];
Everything works fine. Silly mistake eh, but it's all good learning.
I hope someone else who has this problem can profit from my mad panic... :-)
Unless you have specifically set the scale factor of your CAEAGLLayer
to 2.0, OpenGL ES will work in low-res mode on the iPhone 4. With one exception:
Important: A view that is backed by a CAEAGLLayer object should not implement a custom
drawRect:
method. Implementing adrawRect:
method causes the system to change the default scale factor of the view so that it matches the scale factor of the screen. If your drawing code is not expecting this behavior, your application content will not be rendered correctly.
Does that fit your case?
精彩评论