- english
- /
- japanese
methods
- audioReceived()
- audioRequested()
- dragEvent()
- draw()
- exit()
- gotMessage()
- keyPressed()
- keyReleased()
- mouseDragged()
- mouseMoved()
- mousePressed()
- mouseReleased()
- setup()
- update()
- windowEntry()
- windowResized()
variables
The openframeworks engine is contained in the "app" category. The project works, similar to processing, in that you have a base class which extends a class that already exists. In the case of OF, there is a class called "ofBaseApp" which contains various event driven functions. When you create an OF project, you use a main.cpp which is the boot-strap, that kicks off the application and another class, which inherits the properties of ofBaseApp. Essentially, when you write code in the testApp, you are re-writing already defined functions that exist in OF, such as update, draw, etc.
In versions pre 0.06 this class was called ofSimpleApp
audioReceived(...)
void ofBaseApp::audioReceived(float * input, int bufferSize, int nChannels)
If you have setup audio input, via ofSetupAudio, this function will be called when you have one buffers worth of audio. Since you may have requested mutli-channel audio (for example, stereo input), you get not only an array of floating point info, also the size of the buffer, and the number of channels. The size of input (the float array with audio data) is: bufferSize * nChannels; The data will come interleaved, so if, for example, you request 2 channel (left / right) input, the samples come:
l r l r l r l r l r ....
0 1 2 3 4 5 6 7 8 9 ....
so to access an individual sample "n" for channel "j" , you could write something like:
input[n*(nChannels) + j];
audioRequested(...)
void ofBaseApp::audioRequested(float * output, int bufferSize, int nChannels)
If you have setup audio output, via ofSetupAudio, this function will be called when the system needs one buffers worth of audio. Since you may have requested mutli-channel audio (for example, stereo output), you get not only an array of floating point info, also the size of the buffer, and the number of channels.
draw()
void ofBaseApp::draw()
This function gets called regularly just after update. It's where you draw things:
void draw(){
ofSetColor(255,255,255);
ofNoFill();
ofRect(20,20,100,100);
}
exit()
void ofBaseApp::exit()
Add this function to your testApp to have it called at the moment before the app is terminated. This is useful for doing cleanup stuff or making sure files are saved before the app terminates.
keyPressed(...)
void ofBaseApp::keyPressed(int key)
This function gets called when a key is pressed. The value key can be tested against:
void keyPressed(int key){
if (key == 't'){
; // do something
} else if (key == ' '){
; // do something else
}
}
There are more complicated character codes, for keys such as F1-F12, Down, Enter: OF_KEY_BACKSPACE, OF_KEY_RETURN, OF_KEY_PRINTSCR, OF_KEY_F1 - OF_KEY_F12, OF_KEY_LEFT, OF_KEY_UP, OF_KEY_RIGHT, OF_KEY_DOWN, OF_KEY_PAGE_UP, OF_KEY_PAGE_DOWN, OF_KEY_HOME, OF_KEY_END, OF_KEY_INSERT
keyReleased(...)
void ofBaseApp::keyReleased(int key)
This function gets called when a key is released. The value key can be tested against:
void keyReleased(int key){
if (key == 't'){
; // do something
} else if (key == ' '){
; // do something else
}
}
There are more complicated character codes, for keys such as F1-F12, Down, Enter: OF_KEY_BACKSPACE, OF_KEY_RETURN, OF_KEY_PRINTSCR, OF_KEY_F1 - OF_KEY_F12, OF_KEY_LEFT, OF_KEY_UP, OF_KEY_RIGHT, OF_KEY_DOWN, OF_KEY_PAGE_UP, OF_KEY_PAGE_DOWN, OF_KEY_HOME, OF_KEY_END, OF_KEY_INSERT
mouseDragged(...)
void ofBaseApp::mouseDragged(int x, int y, int button)
This function gets called when the mouse is moving and the button is down. The button variable can be used to test against left or right button drags. You also receive the x and y corrdinates of the mouse.
mouseMoved(...)
void ofBaseApp::mouseMoved(int x, int y)
This function gets when ever the mouse moves. You receive the x and y corrdinates of the mouse.
mousePressed(...)
void ofBaseApp::mousePressed(int x, int y, int button)
This function gets called when the mouse is pushed down. The button (left, right, center) is passed in, along with the x and y corrdinate.
mouseReleased()
void ofBaseApp::mouseReleased()
This function gets called when the mouse is released.
mouseReleased(...)
void ofBaseApp::mouseReleased(int x, int y, int button)
This function gets called when the mouse is released. The button (left, right, center) is passed in, along with the x and y corrdinate.
setup()
void ofBaseApp::setup()
This function gets called once, just at the start of the app. It would be a good place, for example, to allocate variables or load in any files.
update()
void ofBaseApp::update()
This function gets called repeatedly. It gets just before draw, so it is an ideal place to do any updating of variables. For example, imagine you have a varibale already defined in your testApp.h called "xpos"
void setup(){
xpos = 0;
}
void update(){
xpos += 1;
if (xPos > ofGetWidth()) xPos = 0;
}
void draw(){
ofRect(xPos, 30,10,10);
}
windowResized(...)
void ofBaseApp::windowResized(int w, int h)
This function gets called when ever we resize the application window. You receive the new width (w) and the new height (h) of the window.
int mouseX
int ofBaseApp::mouseX
Variable mouseX contains information about the current x coordinate of the mouse.
Last updated
Friday, 24 May 2013 22:58:44 UTC
-
3542d4882393b0dfe2d0a44ca5a8c93c980f5eef

