mpatric.com

OpenGL

Posted Tue 10 Jan 2012 by Michael Patricios , 0 comments

I've started using TexturePacker from Code'n'Web. There are versions for several platforms (including Mac OS X) and it can be easily integrated into your XCode build toolchain. It can also create standard definition textures and atlases from the high definition (i.e. retina-display) texture, and much more.. It has saved me a lot of time - if you're building a game with lots of sprite atlases, take a look at this tool. Well worth the US$24.95 asking price for the full version.

TexturePacker

Posted Tue 22 Nov 2011 by Michael Patricios , 0 comments

Continuing with my extensions to Apple's Texture2D class, this post is about extending the sprite sheet functionality in part 2 to render sprites of arbitrary size indexed by an atlas. This is more flexible than having all sprites of the same dimension, laid out uniformly in a large texture image. You can even have overlapping sprites and do other funky things as you're in full control over exactly which part of the texture to render.

For example, the following texture atlas is an extension of the sprite sheet used in part 2 and contains sprites of different sizes laid out in no particular way in the image:

Texture atlas

Posted Tue 01 Nov 2011 by Michael Patricios , 0 comments

Continuing with my extensions to Apple's Texture2D class, this post is about extending it to render a sprite from a sprite sheet, which is basically just rendering only part of the texture. Sprite sheets are useful for storing all of the frames for an animated sprite, or simply for storing multiple images in a single texture. It's not only convenient, but can have a positive effect on performance as the texture does not need to be changed from one sprite to the next (although I haven't made this optimisation in the example code, which selects the texture each time).

This simple implementation requires all the sprites to be the same size, laid out from left-to-right and top-to-bottom in the texture. For example, the following sprite sheet was created using some sprites from Prince of Persia:

A sprite sheet

Posted Fri 21 Oct 2011 by Michael Patricios , 1 comment

The Texture2D class was included with Apple's CrashLanding iOS sample application. Many developers pulled it out of this sample app to use in their own apps as a quick and easy way of rendering 2D images of any size and a variety of colour formats in OpenGL. I find it useful, particularly when prototyping ideas, however the class is limited in its functionality. I developed a small set of extensions for Texture2D for my own purposes and thought others might find them useful. This post describes how to extend Texture2D to allow you to rotate it about its center by an arbitrary angle. The Objective-C code is available on github.

Texture2D rotation screenshot

Posted Fri 15 May 2009 by Michael Patricios , 0 comments

On the iPhone it seems to have become commonplace to use a NSTimer to trigger redraws on OpenGL ES applications when displaying a changing or animated scene. To run smoothly, a frame rate of 30fps or higher is generally aimed for (60fps being the maximum, limited by the iPhone hardware refresh).

Relying on a timer to fire the code that renders the frame has its pros and its cons. The pros are simplicity and having everything in the same thread of execution (or runloop) means not having to worry about concurrency issues. The cons are what I'm more interested in..

Page 1 of 1