Archive for the ‘OpenGL ES’ Category

OpenGL ES 1.1 and the iPhone

Wednesday, December 3rd, 2008

What can make an iPhone developer sulk and refuse to program for two hours?  OpenGL ES is the answer, and it has nothing to do with OpenGL ES per se. 

Largely it’s my fault.  I should have done my research upfront. But with all the talk of the OpenGL ES 2.0 standard, I started to assume that it was supported on the iPhone.  After three hours of learning about vertex and fragment shaders in OpenGL ES 2.0, and writing a few to render a 2D blob for my upcoming iPhone physics engine (more on this later..) I got stuck trying to make it work on the iPhone itself.  

Not surprising really.  The hardware in the iPhone only supports the OpenGL ES 1.1 standard, and as such the API has no calls to any vector or fragment program related goodness.  

Lucky for me, I was just trying to do some shadows and shading of 2D sprites, so I could kinda fake it using some blending and scaling, but I guess the more adventurous effects will just have to wail until the next iPhone generation or later. 

So before you end up crossed armed and sulking as hard as you can at your computer, only do things based on the 1.1 standard, not the 2.0.

iPhone/iPod Accelerometer Issues

Monday, November 17th, 2008

If you’re struggling with odd behavior from your device’s accelerometer ‘every now and again’ then you’re not alone.  

This post comments on the problem and some work arounds, and this is what I’ve found:

Problem:

A few devs out there have noticed the following symptoms

  • The accelerometer will not respond via the delegate at all in your app about 5% of the time when running your app
  • When combined with OpenGLES surfaces, the first drawn frame will be drawn between every new frame drawn to the surface.  This results in a flickering effect where a ‘ghost’ of your initial drawing is interlaced with your normal frames.  

Although some have reported these two problems being one and the same, I found them to be quite separate. I think many people are using the accelerometers+OpenGLES for games, and because the problems happen infrequently they seem related.  I could be wrong of course.  For the same reasons I could just be imagining that they aren’t related.

Work-arounds (not really solutions):

Accelerometer not working

For the accelerometer, many have found (and I have too) that the problem seems to go away if you set the update frequency and delegate much later on in your app.

[[UIAccelerometer sharedAccelerometer] setUpdateInterval: (1.0 / kAccelerometerFrequency)];

[[UIAccelerometer sharedAccelerometer] setDelegate:self];

Typically, you’ll call the above lines in

 - (void)applicationDidFinishLaunching:(UIApplication *)application

but that’s what causes the problems. Anyones best guess is that it just takes too long for the accelerometer to get ready some times and it just ignores your set delegate request. 

Flashing graphics

I can’t confirm that this fix works, but some have reported that using kEAGLColorFormatRGBA8 instead of kEAGLColorFormatRGB565 on your OpenGLES surface will stop it happening.  I’ll give it a try and post my results here. If anyone can confirm or deny this fix, we’d love to hear from you.