Tutorial

Mar 29 11:31

Simple openFrameworks application on iPhone Sample 1

This is a tutorial in getting a very simple openFrameworks application running on iPhone with basic graphics, multitouch and accelerometer support (and one might say a simple particle system too!).

  • 10 Balls are moving around on screen and bouncing off the edges.
  • You can touch the screen with multiple fingers and drag the balls around (multitouch support)
  • You can tilt the iphone and the balls fall in that direction (accelerometer support).

...and all of this without touching a line of Objective C. It is actually one of the samples included in the ofxiPhone download - iPhone Touch+Accel Example. You can find it in the examples folder of the download, so if you load and run that project you can see the finished result. The code below is straight from that sample, warts and all :P

Mar 27 09:01

Developing for iPhone using openFrameworks and ofxiPhone

Note: Everytime I mention iPhone, I am in fact referring to iPhone & iPod Touch running OS 2+.

Update 29/03/2009

Just posted a simple example application source code and walk-through which can be found here.

 

Update 27/03/2009

openFrameworks 006 is now officially released! You can download a fat package for your system from www.openframeworks.cc, mac/linux/windows and now iPhone. I do recommend you keep an eye on the ofxiPhone SVN for updates and fixes.

 

What is this and what does it do?

ofxiPhone (along with ofxMultitouch & ofxAccelerometer) are addons for openFrameworks 006+ that allow you to develop for iPhone in plain old C/C++ just as you would on a normal desktop (mac, linux, windows). This means using the normal testApp.h, testApp.cpp, main.cpp; setup(), update(), draw(), mousePressed(), ofImage, ofTexture etc. and any other C++ classes you may have created. It also means that you can reuse your exact same code running on your desktop (mac osx, windows, linux) unchanged on the iPhone by just copying across your testApp.h, testApp.cpp, main.cpp and other source or resource files you may be using.

Feb 05 15:36

NSArray vs. C Array performance comparison Part II - makeObjectsPerformSelector

NSArraySpeedTest2.PNG

In Part I, I compared the random access performance of a C float* to an NSMutableArray of NSNumbers, and on average the float* performed more than 400 times faster than the NSMutableArray. While those figures are accurate, they don't represent the optimal way of using NSArrays. NSNumbers can also be slow and there are faster linear enumeration methods than objectAtIndex. So I thought I'd modify the example using custom objects and sending messages to all objects, using floats in both cases. Note: these tests are conducted on an iPhone 3G as that's the target platform I was interested in.

Feb 05 14:57

NSArray vs. C Array performance comparison

NSArraySpeedTest.PNG

The classes provided by Cocoa for handling data sets (NSDictionary, NSArray, NSSet etc.) provide a very nice interface for managing information, without having to worry about the bureaucracy of memory management, reallocation etc. Of course this does come at a cost though. I think it's pretty obvious that say using an NSArray of NSNumbers is going to be slower than a C Array of floats for simple iterations, so I decided to do some tests, and the results were pretty shocking! I wasn't expecting it to be this bad. Note: these tests are conducted on an iPhone 3G as that's the target platform I was interested in.

Jan 12 14:34

Memory Management with Objective C / Cocoa / iPhone

Now that the iPhone SDK is out, iPhone/iPod Touch has sold millions and the App Store is pretty popular, there are many people taking to iPhone and Cocoa Touch development. While the SDK is very well designed and pretty quick to get into, the biggest hurdle is usually the unique language that Apple (and previously NextStep) chose for its development on OSX and iPhone: Objective C. At first glance it looks hideous and unlike anything most people using C based syntax are used to (C, C++, ActionScript, JavaScript, Java, C#, GLSL etc.). But once you get your head around it, you really come to love it and understand why this choice was made.

One of the biggest obstacles most people have to get their head around when they first start Objective C / Cocoa development is the memory management - and it's actually very beautiful when it finally dawns on you how simple it really is (though this may take a couple of proper projects!). In fact, I found it so useful, I wrote a little class for C++ for similar functionality (http://code.google.com/p/ofxmsaof/wiki/ofxObjCPointer).

 

Nov 24 20:51

Vertex Arrays, VBO's and Point Sprites with openFrameworks


UPDATE:


This code was for openframeworks 005. Things have changed for openframeworks 006 and it is a lot simpler now. See the updated example here.


Here is some sample code for using (and comparing performance with) Vertex Arrays, VBO's and Point Sprites with openFrameworks 005 to have half a million particles at 60fps (on Mac Pro) or 1M particles at 30fps. Note you will need to hack the core and change ofTexture to only use GL_TEXTURE_2D and never GL_TEXTURE_RECTANGLE_ARB (hopefully with oF 006 hacking the core will not be necessary).
P.S. More performance can be gained by splitting the particle update into multiple threads or moving onto the GPU.
check testApp::keyPressed to see what keys do what...

Oct 27 03:47

Projection mapping / quad warping with Quartz Composer & VDMX

This is a demo of projection mapping with VDMX & Quartz Composer inspired by deepvisual's tutorial of doing it in modul8 (uk.youtube.com/watch?v=2bRfdn9lNO8).

VDMX unfortunately doesn't have this feature built-in, but fortunately has beautiful integration with Quartz Composer - allowing me to build a quad warper in QC using a GLSL vertex shader, which should be super fast.

Also, around the 4:30 mark you'll see me masking the video on the box in the back. This is also using a custom Quartz Composition which allows 4 point mask creation. Usage is almost identical to the QuadWarper, but instead of warping the image it just applies a mask, or you can invert the mask and it cuts a chunk out. You could do the same by creating new layers, grouping, using as a layer mask etc. but its a a bit more hassle I think. Using the QuadMask is a lot quicker and you can put multiple QuadMasks on the same layer to draw more complex masks.

Aug 21 21:42

Realtime GPU based depth-of-field & backlight in Processing with GLSL v0.1

This is a very early version of a GPU based depth-of-field GLSL shader and sample Processing code. Adjust some parameters and it can also be used to give the scene a nice backlight/glow effect.

Aug 05 21:09

Quartz Composer Math vs Expression vs JavaScript performance comparison

I've always wondered (well at least since Quartz Composer 3.0 was released with Leopard) the performance difference between using the new and much easier to use Math Expression patch, and the old Math patch - and in fact compared to using JavaScript.

So I created the attached test composition and found some surprising results (at least I found them surprising, though in retrospect I can understand why :P).

First of all, all 3 methods are pretty quick, and are unlikely to be a bottleneck. Unless you are using the operations in an Iterator patch with a lot of iterations you won't notice any difference.

The figures below are for 2nd gen 2.33Ghz Macbook Pro:

Jul 24 17:04

Quartz Composer 3D Carousel (and loading images within an iterator)

Quartz Composer is a great piece of software for many things. It has a lot of features which really allow you to create amazing things very quickly. It also has some 'features' which allow you to lose your hair very quickly. One of these 'features' is loading images from within an iterator.

You'd think it was quite straightforward, just send a different string (either generated within the iterator or loaded from XML etc.) to the Image Downloader, but alas QC has other plans. It always loads the same image whatever string you send it!

Apr 02 09:26

VDMX Springy Plugin

springy.jpg

In this previous post I mention creating data-source plugins or processing existing data-sources for VDMX using Quartz Composer. Well the specific example I've given in that post isn't that useful, simply does 1-x^2.

I've just created something which may be a bit more useful, its a springy smoothing patch. So you can attach springlike behaviour to data-sources and modify spring stiffness and damping. Here's the JavaScript:

Mar 28 22:11

Using Quartz Composer to create VDMX plugins to process VDMX Data Sources

The current latest version of VDMX5 (0.6.2.7) now has the brilliant (undocumented) capability of using Quartz Composer patches as plugins (in addition to clips, effects and text sources).

What you need to do is:

  1. Create a Quartz Composer patch with a published input, and a published output... with JavaScript or Maths nodes inbetween.
  2. Plop your QTZ in your VDMX/plugins folder
  3. Create an instance of your plugin from the Plugin Manager (at the moment you need to restart VDMX for the plugin to appear I think, I'm sure this will be addressed quite soon).
  4. Assign any VDMX data source to the input of your QTZ plugin.
  5. Assign the ouput of your QTZ plugin as a data source to and slider.

et voila! beautiful. I've attached my sample files...

Jan 16 02:08

Bits, bytes, nibbles, binary and hex.

binary.jpg

This article will start with the basic definitions of bits, bytes etc, go through how data is stored in bits and bytes, and eventually discuss how the binary and hexadecimal number systems work, how to convert between the two and decimal and how that can be useful. Lays a foundation for later articles...