01.02.2014 Views

Objective-C Fundamentals

Objective-C Fundamentals

Objective-C Fundamentals

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Scripting languages: Lua and Ruby<br />

321<br />

if (image == nil)<br />

NSLog(@"Do real error checking here");<br />

GLuint width = CGImageGetWidth(image.CGImage);<br />

GLuint height = CGImageGetHeight(image.CGImage);<br />

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();<br />

void *imageData = malloc(height * width * 4);<br />

CGContextRef context = CGBitmapContextCreate(imageData, width, height,<br />

8, 4 * width, colorSpace,<br />

kCGImageAlphaPremultpliedLast | kCGBitmapByteOrder32Big);<br />

CGColorSpaceRelease(colorSpace);<br />

CGRect imageRect= CGRectMake(0, 0, width, height);<br />

CGContextClearRect(context, imageRect);<br />

CGContextTranslateCTM(context, 0, height - height);<br />

CGContextDrawImage(context, imageRect, image.CGImage);<br />

glTexImage2D(GL_TEXTURE_2D 0, GL_RGBA, width, height, 0,<br />

GL_RGBA, GL_UNSIGNED_BYTE, imageData);<br />

CGContextRelease(context);<br />

free(imageData);<br />

[image release];<br />

[texData release];<br />

Technologies such as the Corona SDK are opening iPhone application development<br />

to a wider range of people; development isn’t necessarily restricted to those with a<br />

strong programming background. A key premise to this type of technology is that the<br />

higher-level scripting languages make development more accessible and forgiving<br />

than in languages in which hard-to-detect-and-diagnose errors can occur (such as<br />

<strong>Objective</strong>-C, which allows you to get closer to the hardware). In this case, the trade-off<br />

of not having immediate access to all hardware of the operating system features can<br />

be deemed to be acceptable. If Lua isn’t your cup of tea, chances are, with a little<br />

research online, you’ll be able to find an equivalent solution for your language of<br />

choice. For example, Ruby developers can use an open source framework called<br />

Rhodes (http://rhomobile.com/products/rhodes/) to develop native applications<br />

that work across a number of mobile platforms (iPhone, Windows Mobile, RIM,<br />

Symbian, Android, MeeGo, and Windows Phone 7) while working with device capabilities<br />

such as GPS, PIM information, camera, mapping, signature capture, and Bluetooth.<br />

The trade-off in using a platform such as Corona is that you may be restricted to a<br />

particular subset of device features supported by the product. Using a similar argument<br />

to that used for web applications, scripting languages will potentially always lag behind,<br />

if only because they require a wrapper to be developed with every API the developer<br />

wants to be accessible from the scripting language. This is especially true when you<br />

consider that many of these platforms also attempt to be cross-platform solutions so, in<br />

some cases, they purposely don’t expose a feature of a specific platform if that feature<br />

would be hard or impossible to provide on another supported device type. You, in<br />

effect, obtain a lowest-common-denominator development platform.<br />

Scripting languages also have to be careful not to run afoul of the iPhone OS SDK<br />

license agreement terms, which every developer must accept in order to develop and

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!