Archive for the 'Programming' Category



03
Nov

Code: OpenGL Bitmap Fonts

Today, we draw your attention to some work-in-progress code that could be of use if you’re interested in using fonts in your OpenGL ES application that aren’t available on the iPhone. It’s called OpenGL ES BitmapFont, intuitively enough, and is simple to use

// loading a font

m_pScoreFont = [BMFont alloc];
[
m_pScoreFont loadFont:@"font.xml"];
[
m_pScoreFont setTexture:[TextureManager loadTexture:@"font_00.png"]];
[
m_pScoreFont setRotation:-90.0f];
[
m_pScoreFont setScaling:0.005f];

// printing some text

[m_pScoreFont print:@"SCORE: 0" posX:0 posY:0.8f];

although apparently there’s a few issues to work out still

Known issues of Version 0.1:

  • color changing not working
  • lower-characters are not getting placed correctly

and getting the texture to load requires the use of the Windows Bitmap Font Generator application from AngelCode.com. Still, hey, it’s a start!

02
Nov

Library: RegexKit

Here’s another useful package to stick in your iPhone programming toolbox: the RegExKitLite framework, which wraps the PCRE library in a vast array of Cocoa-oriented conveniences:

RegexKit is an Objective-C framework for regular expressions:

  • Support for Mac OS X Cocoa and GNUstepMac OS X 10.4 or later required.
  • Mac OS X Universal Binary, including 64-bit support on Mac OS X 10.5.
  • No sub-classing required. Seamlessly adds regular expression support to all NSArrayNSDataNSDictionaryNSSet, and NSString Foundationobjects with a rich set of Objective-C category additions.
  • Unicode enabled. Full Unicode support for NSString objects.
  • Extensive, high quality documentation.
  • Full source code with a BSD license.
  • Uses the BSD licensed PCRE Perl Compatible Regular Expressions library for the regular expression engine.

Tuned for high performance, including such features as:

  • Caches the compiled form of the regular expression for speed.
  • Multithreading safe, including multiple reader, single writer multithreaded access to the compiled regular expression cache.
  • Makes minimal use of heap storage (ie, malloc() and free()), instead allocating most temporary buffer needs dynamically from the stack.
  • Uses Core Foundation directly on Mac OS X for additional speed.

Includes support for Mac OS X 10.5 Leopard:

  • 64 bit support. Pre-built for ppc, ppc64, i386, and x86_64.
  • Garbage Collection enabled. Complete support for Leopards Garbage Collection feature.
  • Integrated Xcode 3.0 documentation. Get real time API information via the Research Assistant.
  • Collection of instruments for Instruments.app.

Everything you need to support regular expression programming goodness!

And if you’re not so familiar with this whole regular expression thing, we’d like to ever so subtly draw your attention to the general programming resources page of the Under The Bridge Store, where you can find the classic O’Reilly Mastering Regular Expressions, which should be on the bookshelf of every serious programmer of every platform out there, not just the Mac/iPhone world!

h/t: iphonesdk!

30
Oct

Code: SMTP Client

Ever wondered about how to send email directly from your iPhone application? Personally, we’re big fans of the do a POST to your server and have it send the mail for you method on the occasions when we’ve had the task of doing something of that sort, but in case you’d prefer to have your application completely standalone, today we point you at the skpsmtpmessage library newly posted on Google Code:

 

This code implements a quick class for sending one off messages via SMTP on the iPhone. Will probably work under Cocoa on Mac OS X as well.

Simple and to the point. And so is the code!
h/t: iphonesdk!
27
Oct

Sample Code: RSS Reader

Here’s a little tutorial of possible utility; how to build an RSS reader for the iPhone!

Whilst that is a pretty straightforward thing to do, this is a little interesting in that it demonstrates the use of NSXMLParser, flying in the face of what appears to be conventional wisdom that one should rely on the cross-platform libxml2 for their XML-parsing iPhone development projects. And people have gone to some work to make that easier with the TouchXML library which, in case we didn’t mention it in our earlier report, is part of the ever more useful touchcode repository over at Google Code.

‘Course, either of the above — or for that matter, anything at all — are probably better than the last time we had to get into that XML parsing thing a lot, which was struggling to make Xerces work in a large cross-platform source base. There were some very … interesting … issues trying to get wchar-based Windows twaddle and OS X style (also known as the “correct” or “real”, type) of characters to work together. Yeeesh. Well out of that, we are!

26
Oct

Unity for iPhone

Just a quick note today that the Unity game development platform is now shipping an iPhone version.

Personally, we just find it hard to get worked up about these kinds of environments, since they always seem to turn out to not quite allow what you actually want to do; but hey, at least the option’s open for us now!

25
Oct

Bar coding followup

Couple followups for you on our post yesterday about resources for bar code parsing on the iPhone:

First off, web guru extraordinaire Leif Jason points out that the macro vision problem with one’s iPhone has, in fact, been solved!

Slide the Clarifi lens into place over the built-in lens of your iPhone. Your macro and close-up shots are instantly finer in detail, more accurate in color. With Clarifi’s lens, your iPhone can image an entire business card with astounding clarity. Slide the lens aside for normal photography. WIthout Clarifi, iPhone requires about 18 inches to focus properly. Slide Clarifi’s lens into place and you can move in to 4 inches for crisp detail and great pictures.

A useful accessory, indeed. Buy yours now!

Next, another code tip from authoress Erica Sadun — yes, that’s twice in a week, which is probably a good indication that we should get around to checking out her well-received iPhone Developer’s Cookbook Real Soon Now — a treatise on how to do full screen image preview and grab the image directly.

I’m not big on the whole Image Picker Camera interface. I hate how slow it is and how it prevents you from scraping the screen. So here’s my work around. In the following code, I scan down the UIImagePicker presentation to find my way to the actual preview window.

First, I build my camera controller…

Next, I add a delayed call to tell the image picker to update itself. This allows time for the image picker to load before I start messing with its views…

The update adds a bar button item to the navigation bar and removes the overlay leaving just the preview displayed…

This allows me to snap a copy of the screen as desired. 

This would make the process of providing images to your recognition code much more conveniently straightforward to the user than relying on conventional APIs for taking individual images; and it fits much better with the workflow of actually scanning something to have a full screen preview that goes away by itself when a usable image is found.

There you go — we’ve sorted out ways to address pretty much all the obvious roadblocks to putting together a bar code reading iPhone application. Now, anybody have any good ideas what to do with one?

24
Oct

Bar coding

So this iPhone walks into a bar … no, wait, it takes a picture of a bar code. And then it proceeds to do something clever with it. That’s a fairly interesting application space, yes? Well, here’s a roundup of resources to help you along with that!

First off, there’s the Zebra Crossing project at Google Code:

ZXing (pronounced “zebra crossing”) is an open-source, multi-format 1D/2D barcode image processing library implemented in Java. Our focus is on using the built-in camera on mobile phones to photograph and decode barcodes on the device, without communicating with a server. We currently have production-quality support for:

  • UPC-A and UPC-E
  • EAN-8 and EAN-13
  • Code 39
  • Code 128
  • QR Code

We also have experimental support for the DataMatrix format.

Unfortunately, it’s written in Java; however, they do have an iPhone client off the ground, currently supporting QR Code, so there’s something to work with there at least.

Another option is to work from the desktop downwards; the great folks at Bruji who do a variety of ThingPedia applications have freed the source to their barcode scanning engine:

The barcode scanner project, written in Cocoa, is for scanning barcodes on books, DVDs, CDs and video games as well as most other kind of EAN or UPC barcodes. It is part of our programs - DVDpedia, Bookpedia, CDpedia and Gamepedia - and is also used by Books. The code is available for free in the hopes that it’ll be useful to other Mac developers.

And they even offer a $500 bounty if you can improve the code!

Before you get too excited with the possibilities here though, we should note that there is a body of opinion which holds that the optical properties of the iPhone camera will make it challenging to reliably decode ISBN or other 1-dimensional bar codes due to their small feature size, at least unless you attach some kind of macro lens. But hey, if it was easy, anybody could do it, right?:  

h/t: iphonesdk!

19
Oct

More Core Animation

As a companion to yesterday’s post, here’s another Core Animation + iPhone snippet: 3D Transformations on iPhone with Core Animation!

Apart from getting all my existing CA examples onto the iPhone I’ve also been toying with what the best way to build out the ‘photo city’ demo from WWDC 2008 would be (my next Core Animation screen cast series). The basic idea of the demo was that you had a set of perhaps 30 or 40 images, the images were combined into cubes and the cubes were used to make a ‘city’. After getting a basic cube working I got distracted by some of the stuff I did to make the demo. Namely I finally got around to porting the OpenGL trackball example code to Core Animation.

For those that are not familiar with the trackball example; the idea is that you have a transparent sphere around your scene, you can move the scene around by moving the trackball. As you move your finger to the right it pushed this imaginary sphere around its center to the right (exposing the left side of the scene).

Make sure to follow the “existing” link above for general Core Animation stuff as well as the trackball controller talked about in that article. Nifty stuff, this Core Animation, yes indeedy!

18
Oct

Sample code: Desk Jockey

Here’s a nice little project for you to dig around in if you’ve been checking out the snazzy stuff you can do with Core Animation – heck, you even bought the book — and been meaning to get into it seriously Real Soon Now. Not that we know anybody like that of course, but just in case you do, have them check this piece from Benjamin Ragheb out, called Desk Jockey:

On October 8, 2008 I gave a presentation at the New York City iPhone Developer Meetup on using Core Animation to design games. Specifically, the talk was focused on creating a scene using CALayer and then responding to touch events so that certain layers can be dragged around the screen.

Download (3.2 MB) the Xcode project and slides.

For your trouble you’ll get a reasonably clearly written exposition of how to mix Core Animation with interactivity on the iPhone, along with a sample project demonstrating it in action:

Pretty cool stuff, this Core Animation, for not very much code. Definitely worth checking into. And if you do, a nice gesture to show appreciation would be to buy Benjamin’s programs FatWatchicon and Ruboku
icon, we definitely want to support people who share the knowledge, don’t we?

h/t: iphonedev!

16
Oct

Asterope postmortem

Here’s an inspirational story for you: a detailed chronology of the journey of the game Asterope from concept to the App Store by way of … the Google Android Challenge!

It actually took a while until I started working on the game for real. The deadline for the Google Android Challenge was the last day of February, if I recall it correctly, and although the idea was vividly with me for January I could not get myself to start working on it. I think it had to do with me needing some time to rejuvenate after having stopped working part-time. I almost gave up on the idea with the deadline nearing so quickly, but then Google decided to postpone the deadline to April 14th after they released an update to their SDK. This got me motivated to do it – to take action on the opportunity!

That didn’t work out quite as hoped — although it did get rated in the top quarter which is, well, better than not being in the top quarter, but that’s about it; but then along came the iPhone!

After the iPhone SDK was released I instantly knew that I had to port my game to the iPhone. I could not let Asterope sit still and collect dust on my hard drive…

I instantly fell in love with the device, it had the most beautiful UI I had ever seen on a phone. And it just worked! I’ve had seven Nokias in the past but never have I been as impressed with a phone as I was with the iPhone. It’s just a huge step forward from anything previously on the market.

In late August I had the iPhone, a Mac Mini to develop it on and time to make it happen. Time to roll up my sleeves. I could not let myself pass on this opportunity. And I tell you it felt almost scary knowing I might have everything I need to make a commercial game with potential to make a lot of money.

Heartwarming story, isn’t it? I think we should all reward this young fellow’s ambition by buying his game immediately:

Asterope in the App Store!icon

h/t: Slashdot!