openframworks x mobile
DESCRIPTION
I gave a talk in coscup 2011. My topic is about using openframeworks in mobile application. :) You can download the demo code from github. https://github.com/janetyc/CosBirdTRANSCRIPT
Openframeworks x Mobile
2011.08.20黃怡靜
Janet Huang
@janetyc
why I am here...
why openframeworks...
openFrameworks is an open source C++ toolkitfor creative coding.
Computer Technology “is not a tool;
it is a new material for expression”
Maeda, J. (2004). Creative Code. New York: Thames & Hudson Inc.
Openframeworks
MediaHardware
Communication
cross platform
mac iphone windows linux android
Pros
experimentaleasy to use
interactivity
not completeopen source &
Cons
rtAudio
openGL
freeType
freeImage
quicktime
graphic
audio input/output
fonts
image input/output
video playing
basic libraries
sequence grabbing
OF structure
apps libsaddons
openframeworks
addons examples
OF component
main.cpp
testApp.cpp
testApp.h
main.mm
testApp.mm
testApp.h
osx app iphone appandroid app
#pragma once
#include "ofMain.h"#include "ofxiPhone.h"#include "ofxiPhoneExtras.h"
class testApp : public ofxiPhoneApp {!public:! void setup();! void update();! void draw();! void exit();!! void touchDown(ofTouchEventArgs &touch);! void touchMoved(ofTouchEventArgs &touch);! void touchUp(ofTouchEventArgs &touch);! void touchDoubleTap(ofTouchEventArgs &touch);! void touchCancelled(ofTouchEventArgs &touch);
! void lostFocus();! void gotFocus();! void gotMemoryWarning();! void deviceOrientationChanged(int newOrientation);
};
testApp.h
#include "testApp.h"
//--------------------------------------------------------------void testApp::setup(){!! // register touch events! ofRegisterTouchEvents(this);!! // initialize the accelerometer! ofxAccelerometer.setup();!! //iPhoneAlerts will be sent to this.! ofxiPhoneAlerts.addListener(this);!! //If you want a landscape oreintation ! //iPhoneSetOrientation(OFXIPHONE_ORIENTATION_LANDSCAPE_RIGHT);!! ofBackground(127,127,127);}
//--------------------------------------------------------------void testApp::update(){
}
//--------------------------------------------------------------void testApp::draw(){!}
//--------------------------------------------------------------void testApp::exit(){
} testApp.mm
//--------------------------------------------------------------void testApp::touchDown(ofTouchEventArgs &touch){
}
//--------------------------------------------------------------void testApp::touchMoved(ofTouchEventArgs &touch){
}
//--------------------------------------------------------------void testApp::touchUp(ofTouchEventArgs &touch){
}
//--------------------------------------------------------------void testApp::touchDoubleTap(ofTouchEventArgs &touch){
}
//--------------------------------------------------------------void testApp::lostFocus(){
}
//--------------------------------------------------------------void testApp::gotFocus(){
}
//--------------------------------------------------------------void testApp::gotMemoryWarning(){
}
//--------------------------------------------------------------void testApp::deviceOrientationChanged(int newOrientation){
}
//--------------------------------------------------------------void testApp::touchCancelled(ofTouchEventArgs& args){
} testApp.mm
touch event
alert engine
How to start ? 1. create a copy of emptyExample in apps folder 2. rename the folder and .xcodeproj file 3. open the project 4. rename target 5. make sure it builds and runs
Let’s do it now.
audio
graphicaccelerometer
touchimage
input output
audio
audio input
initialBufferSize ! = 512;sampleRate ! ! ! = 44100;drawCounter! ! ! = 0;bufferCounter!! = 0;!buffer!! ! ! = new float[initialBufferSize];memset(buffer, 0, initialBufferSize * sizeof(float));!ofSoundStreamSetup(0, 1, this, sampleRate, initialBufferSize, 4);ofSetFrameRate(60);
testApp.mm
void testApp::audioIn(float * input, int bufferSize, int nChannels){! if( initialBufferSize != bufferSize ){! ! ofLog(OF_LOG_ERROR, "your buffer size was set to %i -
but the stream needs a buffer size of %i", initialBufferSize, bufferSize);! ! return;! }!!! // samples are "interleaved"! for (int i = 0; i < bufferSize; i++){! ! buffer[i] = input[i];! }}
setup()
// 0 output channels,// 1 input channels// 44100 samples per second// 512 samples per buffer// 4 num buffers (latency)
accelerometer
ofxAccelerometer.getForce().xofxAccelerometer.getForce().yofxAccelerometer.getForce().z
touch event//--------------------------------------------------------------void testApp::touchDown(ofTouchEventArgs &touch){
}
//--------------------------------------------------------------void testApp::touchMoved(ofTouchEventArgs &touch){
}
//--------------------------------------------------------------void testApp::touchUp(ofTouchEventArgs &touch){
}
//--------------------------------------------------------------void testApp::touchDoubleTap(ofTouchEventArgs &touch){
}
touch.xtouch.y
(0,0)
audio output
ofSoundPlayer bird_sound;
bird_sound.loadSound("weeee.wav");bird_sound.setVolume(1.0f);bird_sound.setMultiPlay(false);
bird_sound.play();
declaration
setup
play
draw image
ofImage head_img; declaration
setup
playhead_img.draw(x_pos, y_pos, width, height);
head_img.loadImage("bird_cos.png");
graphics- OpenGL (desktop)- OpenGLES (iphone)
polygonExample
void testApp::draw(){
ofFill();ofSetHexColor(0x3ABEE3);ofCircle(100, 100, 50);
}
50
http://www.openframeworks.cc/documentation
fun
sound
interactive
game
Cos Bird: an interactive sound game
CosBird
quiet little noisy more noisy angry!
weeeeeeee
Live demo
http://twitter.com/janetychttp://gplus.to/[email protected]
Thanks very much.