A while ago I'd posted an example and source code for using Vertex Arrays, Vertex Buffer Objects and Point Sprites in openFrameworks. This was for openFrameworks 005 and needed some mods to the core and other hacks to get it to do what we needed. In the current version of openframeworks (006+) a lot of the required functionality has been moved to the core and so we don't need the extra classes MSAImage and MSATexture, or to hack the core. The updated example is attached and can be downloaded from below.
P.S. An example on particle system with OpenCL for even more performance (updating the particles on the GPU) can be found here.
I've recently needed to work with Midi Time Code (MTC) and could not find any code to parse the midi messages and construct an SMPTE timecode. Closest I got was finding this documentation (which is pretty good) on how the data is encoded in the bits of 8 bytes sent over 2 SMPTE frames, each byte sent at quarter frame intervals. From that I wrote the code below (I've only really tested the 25 fps). The code is from an openframeworks application but should work with any C/C++ code.
class ofxMidiEventArgs: public ofEventArgs{public:
int port;
int channel;
int status;
int byteOne;
int byteTwo;
double timestamp;
};
#define kMTCFrames 0#define kMTCSeconds 1#define kMTCMinutes 2#define kMTCHours 3// callback for when a midi message is receivedvoid newMidiMessage(ofxMidiEventArgs& eventArgs){if(eventArgs.status == 240){// if this is a MTC message...// these static variables could be globals, or class properties etc.staticint times[4] = {0, 0, 0, 0}; // this static buffer will hold our 4 time componens (frames, seconds, minutes, hours)staticchar *szType = ""; // SMPTE type as string (24fps, 25fps, 30fps drop-frame, 30fps)staticint numFrames = 100; // number of frames per second (start off with arbitrary high number until we receive it)int messageIndex = eventArgs.byteOne >> 4; // the high nibble: which quarter message is this (0...7).int value = eventArgs.byteOne & 0x0F; // the low nibble: valueint timeIndex = messageIndex>>1; // which time component (frames, seconds, minutes or hours) is thisbool bNewFrame = messageIndex % 4 == 0;
// the time encoded in the MTC is 1 frame behind by the time we have received a new frame, so adjust accordinglyif(bNewFrame){
times[kMTCFrames]++;
if(times[kMTCFrames] >= numFrames){
times[kMTCFrames] %= numFrames;
times[kMTCSeconds]++;
if(times[kMTCSeconds] >= 60){
times[kMTCSeconds] %= 60;
times[kMTCMinutes]++;
if(times[kMTCMinutes] >= 60){
times[kMTCMinutes] %= 60;
times[kMTCHours]++;
}}}printf("%i:%i:%i:%i | %s\n", times[3], times[2], times[1], times[0], szType);
}if(messageIndex % 2 == 0){// if this is lower nibble of time component
times[timeIndex] = value;
}else{// ... or higher nibble
times[timeIndex] |= value<<4;
}if(messageIndex == 7){
times[kMTCHours] &= 0x1F; // only use lower 5 bits for hours (higher bits indicate SMPTE type)int smpteType = value >> 1;
switch(smpteType){case0: numFrames = 24; szType = "24 fps"; break;
case1: numFrames = 25; szType = "25 fps"; break;
case2: numFrames = 30; szType = "30 fps (drop-frame)"; break;
case3: numFrames = 30; szType = "30 fps"; break;
default: numFrames = 100; szType = " **** unknown SMPTE type ****";
}}}}
Inspired by the brilliant use of an age old concept in the recent OKGo 'WTF' video, I created this little open-source demo in processing. It works in real-time with a webcam and you can download the app and source from http://www.msavisuals.com/xmas2009
Recently I've been playing a lot with OpenCL, the new API / framework designed to handle cross-platform parallel computing (i.e. a simple way of running code simultaneously on all cores of your CPU, GPU or other processors). Implementations have been cropping up this year in NVidia drivers or ATI drivers, but most famously it's included with Mac OSX 10.6 Snow Leopard.
To cut a long story short I've been working on a simple-to-use C++ wrapper for some of the most common functions, imaginatively called ofxOpenCL and here is a little demo of 1 million particles running at 100-200fps.
NOTE: The Vimeo compression destroys most of the particles, so I suggest downloading the quicktime directly from the vimeo page at http://www.vimeo.com/7332496
This is 1,000,000 particles being interacted on by mouse, updated on GPU (with springy behaviours ) via an OpenCL kernel, data written straight to a VBO and rendered - without ever coming back to host (i.e. main memory + cpu etc.)
Frame-rate is around 100-200fps running on a macbook pro with GF 9600GT. That's 100-200fps on a laptop! (albeit a pretty decent one), but I'm dying to try this on a GF 285 GTX - which has 7.5x the number of cores, 2.5x the fillrate and 3.5x the memory bandwidth - for only £250!!
Originally created to forward UDP TUIO (OSC) messages straight to TCP to be read from within Flash.
This application forwards all incoming UDP messages straight to TCP without touching the data, just a straight forward.(Since version 0.2.1 there is the option to prefix the size of the packet before sending the data to comply with OSC / TCP specifications). This enables applications that don't support UDP (e.g. Flash) to receive the data. Since OSC / TUIO are generally sent via UDP, this enables Flash to recieve those messages in their raw binary form.
Inspired by Roxlu's brilliant openFrameworks wizard for code::blocks I thought I'd have a go at creating similar XCode templates - turned out it's super easy and you can download them below (templates for both desktop applications and iphone applications). Instructions are included in the zip but I'm attaching it below too.
Note: the iPhone template is for the latest version of ofxiPhone from the svn because there are additional files in the current version. (Thanks to everybody for pointing this out).
This is a set of C++ classes for solving and displaying real-time fluid dynamics simulations based on Navier-Stokes equations and Jos Stam's paper on Real-Time Fluid Dynamics for Games. The solver class has no dependencies on openFrameworks and can be used in any C++ project. The drawer class extends ofBaseDraws and contains an ofTexture for seamless integration with openFrameworks drawing routines. Also included in the addon is a ofxMSAParticleUpdater class which allows the fluid solver to be easily plugged into ofxMSAPhysics as a force field.
I've changed the license on my code/libraries etc. to use the revised BSD License instead of GPL. For those not sure what this means: the GPL license required all users of the libraries to license their apps as GPL too. This would mean that you could not distribute your app without distributing the source code as well - and forget about selling apps on the iphone app store. While I think the GPL is very useful (and necessary) for large open-source projects, I feel it's a bit too restrictive for the nature of my libraries (small tools), so I used the revised BSD license which allows you to use the libraries and do pretty much whatever you want with the finished apps.
This is a library for solving real-time fluid dynamics simulations based on Navier-Stokes equations and Jos Stam's paper on Real-Time Fluid Dynamics for Games. While I wrote the library primarily for processing it has no dependency on processing libraries and the source can be used with any Java application.
The video below is a demo of a processing sketch using MSAFluid, being controlled by MSA Remote on iPhone (You can view the video in HD and download a 1080p version at vimeo).
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
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.
ofxMSAPhysics is a C++ 3D particle/constraint based physics library for openFrameworks. It uses a very similar api to the traer.physics library for processing to make getting into it as easy as possible.
Version 2.0a is now available for testing.
Main features include
particles
springs
attractions (+ve or -ve)
collision
replay saving and load from disk (temporarily disabled in current alpha release)
custom particles (extend ofxMSAParticle and add to the system)
custom constraints (extend ofxMSAConstraint and add to the system)
custom force fields (extend ofxMSAParticleUpdater and add to the system)
custom drawing (extend ofxMSAParticleDrawer and add to the system)
148apps.com - 4/5 stars."You will find yourself showing people this application …and then, not getting your iPhone back because they want to keep painting."
geek.com - "I like the fact that the app is not just a port of the website, but includes enhancements which take advantage of the features of the iPhone."
iphonefreakz.com - "...the most jollificating paint app for iPhone and iPod Touch. It’s like getting a Jackson Pollock soul inside you...Definitely worth having it on your phone for. Well worth $0.99"
iPhone adaptation of Miltos Manetas' website jacksonpollock.org (original flash developed by Stamen Design). Save your pictures and send them to jackson@jacksonpollock.org, the best Pollocks will be published in an upcoming book.
The video below shows the basic features of v1.0. In the current version (v1.1) ability to choose your own colors has been added to allow the creation of more controlled paintings like those seen in the images below.
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.
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.
Over the years OpenGL has developed lots of different ways of sending vertex data to the graphics card: Immediate mode (glBegin / glVertex / glEnd etc.), Display Lists, Vertex Arrays, Vertex Buffer Objects etc. The first of these (Immediate Mode) is quite inefficient, so it's been dropped in OpenGL ES and depreciated in OpenGL 3.0. Instead we are to use Vertex Arrays or VBO's (Vertex Buffer Objects). They are way more efficient, but generally not as straightforward to setup and use.
For this reason I wrote a C++ class that wraps up the functionality of Vertex Arrays (and soon VBO's) in an immediate mode style syntax. I.e. you can carry on calling glBegin / glNormal / setColor / glTexCoord / glVertex / glEnd etc. but instead of sending the data on every function call, it just caches them all in client-side arrays, and sends it all in one go when you call glEnd(). Later you can call draw() to redraw the information you've put in. Thus improving performance on desktop systems, and allowing immediate mode style syntax on embedded systems such as the iPhone. (The previous post about the Meshulator uses this class).
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...
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.
Added loop mode configurable from the preferences.plist
-----------------
MSAQTPlayer is a Mega Super Awesome (& mega super basic), fullscreen / multiple output Quicktime player with fast, greater-than-4096-pixels support.
I wrote this app for an installation because I needed to play a 4,800 x 600 Quicktime file across 2 outputs on my graphics card, each feeding 3 triple heads to go into 6 projectors, and I couldn't find a single application that could do it.
Most video applications which can output across multiple video-outs cannot play files larger than the maximum size of a texture (usually 4096 pixels). And even if the movie resolution fits in a texture, they are very slow because they convert each frame to a texture and upload to the graphics card. The only application I found which could play a large file is Quicktime Pro, but that cannot output across multiple video-outs.
MSA QTPlayer is a native Cocoa app which can do this (using QTKit and OSX 10.5) .
This is a demo for a traer like physics library for C++/openFrameworks.
I wrote the lib for a little project with Todd Vanderlin while in Linz, Austria at Ars Electronic 2008 (vimeo.com/1707467). I tried to keep the same API as Traer (so processing code using traer can easily be ported to oF) and it is basically a particle system with springs, attractions, gravity etc (but uses verlet integration instead of RK4).
In this demo I am interacting with the app using the keys:
My Secret Heart is a music and film installation & performance commissioned by Streetwise Opera with music composed by Mira Calix and sound design by David Sheppard. Working with video artists Flat-e, we created a film to accompany the 48 minute performance, as well as versions for an installation and short film.
Streetwise Opera
Streetwise Opera are a charity who use music as a tool to help people who have experienced homelessness move forward in their lives. They run a weekly music programme, resident in 10 homeless centres around the country - and also stage an annual production which gives their performers the chance to star in quality shows where there are high-expectations, no compromise and no patronising. The voices you hear in the music, and people you see in the film, are from Streetwise workshops around the UK. 100+ Streetwise performers also sang at the My Secret Heart premiere at the Royal Festival Hall in December 2008. My Secret Heart is about their story.
The film
The film has an abstract narrative derived from individual conversations with each of the Streetwise performers. It is a direct emotional response to their stories combined with the haunting beauty of Mira Calix's composition. Instead of focusing on a specific plot, the film embarks on a complex journey through various states of emotion, starting from pre-birth through birth, curiosity, exploration, excitement, playfulness; through to fear, anxiety and isolation. While it maintains a relatively dark and eerie mood overall, intertwined with the feelings of desperation are strong elements of hope.
The visuals were designed and created primarily with custom software written in C++/openFrameworks, with some Quartz Composer elements, rendered AfterEffects sequences and live action footage. The custom C++ app is audio-reactive and user-interactive, allowing the visuals to be 'performed' live with full control over the behaviour of the virtual inhabitants of the cylindrical aquarium-like rig.
Over the course of a few months, and after many conversations with Mira Calix and listening to the soundtrack over and over and over again, we decided roughly what the visuals should do and what kind of behaviours we wanted the visuals to perform at specific points in the song. After a lengthy coding period, I had an application that when you ran, did... nothing, but it had the potential to do everything I wanted. The application was a live performance tool with full control over its environment as well as audio playback and control, and an input recording / playback system.
Once the application was complete, I sat down with Robin from flat-e, and pressed 'play' on the app - this started the music playback and the physics recorder. While the music was playing we could control the inhabitants of the virtual world with many sliders, knobs, touchpads, mouse etc. As the music was playing we would respond in realtime by sending messages to make them move gracefully, erratically, flocking together, swimming apart, getting excited, slowing down, speeding up, telling them to die, slowly start twitching, come alive, swim to the surface, sink to the bottom etc - our actions being recorded gave us the ability to later go back and scrub to certain positions in the song and overdub and mix new behaviours we might have missed in the first round. In the end we found that actually we had to do little to no editing. The best overall performance was the one we recorded in a single 50 minute take.
The sensation of performing and recording the visuals was that of actually directing a film with thousands of virtual actors, commanding an army, digital puppetry - an approach I'm sure I will be revisiting in the very near future.
Early tests of visuals on the 'aquarium' (rig built by Gaianova):
A set of C++ template classes for doing various types of interpolations on data with any number of dimensions. You can feed the system an arbitrary number of data (data can be simple types like float, int or complex types like structs, classes), then resample at any resolution, or ask for the value at any percentage along the data - or just draw it - including splines in 3D.
This is useful for creating and drawing splines (in any dimensions), or creating smooth animation paths from keyframes (again, in any dimensions).
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.
I was sitting minding my own business, exploring accumulation buffers in Quartz Composer, when all of a sudden I just zoned out, and next thing I know, I found myself staring at Him on my screen. His Noodly Appendages came down and touched me, and guided my hands, connecting Quartz Composer's very own noodles in His Image.
His Noodly Screen Saver runs on Mac OSX 10.5 (Leopard) and you can download it below.