Archive for the ‘iPhone’ Category

A Tool for Creating OpenGL Animation Textures

Tuesday, May 12th, 2009

Updated Sept 28, 2009: You can now hard-code the number of columns. Also included the full source code.
Updated: I fixed a bug to do with image sizing. The new download is at the end of this post.

I’m in the midst of writing my first iPhone game. I had a need to create an animation from a series of frames I produced in 3DS Max and play them back in the game. I googled the web for the best way to do this and it seems for short animations (less than 50 frames or so) like explosions and rotating asteroids the best technique for OpenGL is to stick them all together on the same texture and just change the displayed coordinates on the polygon I was using. For example:

I began by doing this myself, manually in Photoshop. What a time waster! Every time I wanted to update an animation or tweak it, it represented up to an hour of work just to do the work of resizing and stitching the images together on a grid. I then had the bright idea of automating the process. I wrote a tool in .NET that does exactly that, while preserving the alpha channel of PNG images. It sorts (by filename), resizes, stitches, and outputs the result to a neatly sized PNG graphic that can then be converted to an OpenGL texture. Remember that if you use this tool, the maximum texture size is 1024×1024 so you have to limit your animations to something that will fit in that grid.

I first tried it with an asteroid animation and it worked nicely. I’ve included the asteroid frames in the download for you to use or as an example. I also did it with an animation I made in ParticleIllusion for an explosion:

screen-capture

Now, on the Objective-C side of things, you need to write a class that can take these stitched assets and animate over each frame. I’ve whipped something up using the Texture2D classes provided by Apple (which I’ve augmented somewhat). Three methods are provided:


-(void)setupAnim:(int)pxWidth:(int)pxHeight:(int)frameWdth:(int)frameHt:(int)frmCnt

This takes the pixel width and height of the entire image, as well as the pixel width and height of each frame, and finally the number of frames.


-(void)incFrame

Initially the currentFrame value is set to 0 (the top left frame). You can manually set this property, or use this function incFrame() to bump it up one. When the end is reached, it will loop to the beginning.


-(void)drawFrame:(Texture2D*)animTexture:(float)x:(float)y:(float)width:(float)height:(float)rotation

This will draw the frame using the special Texture2D class I provided with an x,y, width, height, and rotation (in degrees).

If you have suggestions for a better way to do what I’m trying to do – please let me know! This utility is free to download if you find it useful, however.

Below you can see the asteroid in action!

screen-capture1


Free iPhone Toolbar Icons from Glyphish

Monday, April 27th, 2009

iPhone toolbar icons are 24bit PNG files with an alpha channel. Glyphish has posted some royalty-free images you may use in your apps. Be careful not to use any that resembled an iPod or iPhone because app reviewers have shown a dislike for these lately. Get them here.

iPhone Developer Summit: New York June 22

Saturday, April 18th, 2009

The next iPhone Developer Summit will be held in New York City (June 22, 2009), at The Roosevelt Hotel, co-located with the 7th International AJAXWorld RIA Conference & Expo.

The groundbreaking iPhone Developer Summit is chaired by the Editor of iPhone Developer’s Magazine, Ian Thain.

At iPhone Developer Summit, delegates will hear from industry experts about the impact the iPhone is having on delivery of rich content to mobile users. Technical sessions will explore a world of web development opportunities on the iPhone including building social applications, and developing high-quality, iPhone-style web-based GUIs for your applications.

Additionally, expert faculty speakers will help delegates learn about when to use the iPhone SDK and when to develop web applications.

Review of O’Reilly’s “iPhone SDK” Book

Wednesday, April 15th, 2009

I recently was sent a preview copy of O’Reilly’s new book “iPhone SDK” by Jonathan Zdziarski. I’ve looked at a few iPhone development books and this one is OK but hopefully will be better in the next edition. I have some complaints – things I’d like to see in the second edition, but they’re things I hope they fix and reprint because overall this is a good resource.

Audience: Beginners. A little Objective-C would be nice but not required.

What to expect: A tutorial-style introduction to iPhone development that takes very little for granted.

First of all, it’s well organized. The author begins with an excellent top-down discussion of the iPhone OS and the SDK. He also gives a quick introduction to Objective-C if you’ve never done that before. He introduces the MVC pattern, views, controllers, transitions, controls, multi-touch, events, multi-media, geolocation, and gestures.

Things I liked about this book:

  • Great progression from the simple to the complex that introduces many of the important concepts in iPhone application architecture.
  • Lots of complete, atomic examples.
  • Nice clear writing style, although sometimes a bit brief.

Things I hope they fix in the second edition:

  • This is a relatively short book – about 350 pages, and big print – too. There is a lot of room for expansion, and some subjects the author doesn’t cover in depth enough.
  • I think the section on Objective-C is far too brief. As a developer who is new to the Mac platform as well as the iPhone platform, I am learning Objective-C at the same time as the iPhone SDK. I think a couple chapters at least on the basics of the language would go a long ways to improving this book.
  • The book did not adequately explain device provisioning, certs, and AppID’s. You’ll have to figure this stuff out on your own by reading the material provided by Apple.
  • I was disappointed the author spent no time discussing OpenGL programming on the iPhone. This seems like a fairly major subject area conspicuously overlooked.
  • This book came out exactly at the same time that the iPhone SDK 3.0 went to beta, and of course doesn’t cover anything from that. Hard to criticize, but you have to admit the timing is bad. I wish O’Reilly would do something like promise people who buy the book that they’ll get a PDF of the next edition once iPhone SDK 3.0 is released.
  • If they do release a second edition it should definitely cover the new Core Data API, the new mapping stuff, the push API, the general changes to the application model, and the changes to eventing and UIKit.

You can pick up a copy of this book at Amazon for $23.09.

If you would like me or Tyson to review your iPhone, Blackberry, J2ME, Android, Objective-C, JavaScript, Rails, or .NET book please just email me at alexei.white(at)gmail.com.

Free Stanford iPhone Dev Course

Tuesday, April 14th, 2009

This is cool. There is a free iPhone development course available for download through iTunes here. This is being put on by Stanford university. I have yet to watch it but will be.

The general “prerequisite” for the course is a familiarity with C:

“we do strongly recommend that students are comfortable with programming in C, especially with regard to using pointers and general C memory management (malloc/free). Familiarity with object oriented designs and principles are definitely helpful but tend to pose less of a stumbling block than wrangling with pointers in C.”

New iPhones May Be On The Way

Saturday, April 11th, 2009

There’s been a fair amount of speculation since the 3.0 OS was announced that Apple may be planning a hardware update at the same time as releasing OS3.0 on to the world. On the one hand I wouldn’t put it past them. They’re known for aggressive and frequent hardware upgrades but is the world ready to update the phones they just bought a few months ago now (and I’m talking about the 3G)? Well who am I kidding I’ll buy one.

According to Kaufman Bro’s Shaw Wu, there is strong speculation about the possibility of two new phones, both having better battery life and processing power making it possible for them to run more complex apps than before. One of these is likened to a “junior” version with the slower processor, and the other aimed more at serious gamers and business users. [source]

I’m not doubting that Apple will do a hardware update, or that it may happen this summer (I’m actually a little doubtful of that), but the idea of two current-model iPhones with different processing capabilities makes me want to break stuff. As a developer it’s hard enough to think in terms of the limit CPU and UI domain of a phone, but way harder if you want to service that market – and have to write for two completely different devices.

Here is the prediction from Wu:

  • The possibility of two new iPhones with one faster than the other. Both will have better battery life.
  • Production will be boosted to 5 or 6 million units for the quarter. Higher than the 4.5 million units currently produces in this quarter.
  • Possible June or July ship date.
  • More tiered data plans from carriers to counter lightening of demand from a poor economy.

What Framework Should I Use?

Friday, April 10th, 2009

I feel like in the last few years, the amount of real choice has improved for selecting a language to write software in. That’s a good thing, but it does make investing in a platform a bit of a risk. Here is the framework I would use to decide on a language or framework choice.

Desktop Development

I put desktop development into two general categories: business and entertainment. I feel like your choices narrow considerably once you start doing game development and things begin to get a lot more expensive quickly because you need that razor-thin proximity to the hardware. If performance isn’t super important and what you’d really like is your app to run on a lot of different platforms you have a few choices, Java (Swing, Webstart, or otherwise), Adobe AIR (apps running on Flex or HTML / JavaScript), or .NET (compatibility via Mono). Otherwise you’re stuck dealing with OS-native runtimes like .NET, Cocoa, and so-on.

cplat

Mono is interesting, but not quite the write-once compile-often solution it’s made out to be.. there are plenty of catches and as I understand it a hefty learning curve. I personally prefer to work in .NET in Windows, but if I had to write a cross-platform application I’d probably try to find a way to do it in AIR. At this point I’ve written a few applications in AIR using the HTML/JavaScript runtime and dabbled in Flex. You can do a LOT in a very short amount of time, and I’ve seen a lot of big names like PayPal, Salesforce.com, NASDAQ, and so-on. Just check out their showcase.

You’d have a hard time writing a commercially viable game in AIR, though. The 3D API’s are nowhere near as powerful as OpenGL or DirectX running natively, but you could do some pretty decent 2D or 3D puzzle games. AIR is really more for business-applications at this stage. I did write a Jeopardy-clone game at one point for a client that I made some cash on.. which was used at a conference. That was fine – but it was Jeopardy, after all.

Mobile Phone Development (iPhone, Blackberry)

There are a couple ways to approach the mobile handset development problem. Let’s say you wanted to write a version of your app for a phone but didn’t know which handsets to support – where do you start? iPhone uses Objective C, Blackberry uses a version of Java ME, Android uses Java also – are you just supposed to figure out which device your uses use the most and start there? Getting expensive again. You might do that, but the first thing I would do is find out if there is any way on earth I can use a project like PhoneGap to write my app as a web-app with a native shell. It’s that write-once compile-anywhere thing again. PhoneGap really lowers the bar for mobile apps letting you deploy most simple applications to any number of touch-devices.

phonegapsupport

By the time you read this, that chart may be out of date, so definitely visit the site to check it out.

iPhone OS Installation Hell

Monday, March 23rd, 2009

I signed up for the iPhone Developer Program yesterday at the enormous expense of $100 and made the decision to start learning SDK 3.0. At this stage I know absolutely zero Objective C and have never written a program for iPhone, web or otherwise – but you gotta start somewhere, right?

I want to stress that I’m a legitimate user with a full Developer membership (yes I sheepishly forked out the $99 to be a member of this very elite group of upwards of 30,000 suck – er, developers). I downloaded the OS image and installed it – which immediately locked up my phone. It’s telling me now that I need to activate with iTunes. Ok, no problem, I’ll fire up iTunes. Can’t activate, why? Not a member of the developer program. Well I AM, so I go to XCode to provision the phone, but of course I can’t because the phone isn’t activated. It’s a vicious circle. OK had I known then what I know NOW I would have then gone to the Developer Portal and provisioned the phone THERE, but that insight came only hours later.

Eventually I completely bricked the phone. I wouldn’t even turn up in Xcode. OK, so I tried to downgrade.. can’t do that either. I ended up having to put the phone into DFU mode, loading an old OS image, and then using QuickPwn to fix the phone (thanks QuickPwn!). If this happens to you, don’t believe the dudes from Apple or on the forums – it IS possible to downgrade your phone using the general method I described.

I don’t think I’m supposed to talk about OS3.0 much so I won’t, but I will say that I’m looking forward to doing some development and learning the ropes of Objective C.

New iPhone imminent?

Monday, June 2nd, 2008

According to Forbes, Apple “has been quietly positioning millions of units of a mysterious new product–almost certainly the new iPhone–in key markets since March.” Despite this, there has been no public announcement or images released of this new device.

It will almost certainly support 3G – a faster mobile internet system (so you’ll finally be able to actually watch those YouTube flicks while on the bus). Probably the storage capacity of the device will be increased too. If we’re lucky they’ll have done something about battery life too – although that seems doubtful with the demands of the 3G circuitry and any additional storage they intend to cram on there.

iPhones of the Future – Solar powered?

Tuesday, May 27th, 2008

Mobile devices from Apple in the future may have the ability to draw power from the sun for longer battery lives. This revelation came to light today as people at Trade the News (a better article is here) noticed that recent patent applications from Apple included technology to harness sunlight.

While it may be a ways off in the future – photovoltaic cells beneath the touch-screen could add hours to battery lives – making devices like the iPhone much more practical for business users – who have been complaining about the limitations of the small battery for users who are constantly on the go. This is one of the major reasons consumers won’t be leaving Blackberry anytime soon for business communication.

Of course the bigger story here is that with solar energy and using other types of micro-energy devices we could one-day take our mobile devices completely off-grid. It has some appeal, if you can get over the idea that you’ll never again have the excuse ’sorry my iPhone battery was dead.. wasnt receiving any calls’.



© All rights reserved.