a gentle introduction to openframeworks

63
a gentle introduction to openFrameworks Becky Stewart [email protected] beckystewart on slideshare

Upload: becky-stewart

Post on 12-May-2015

5.039 views

Category:

Technology


5 download

DESCRIPTION

The basics of openFrameworks within the context of Arduino and Processing. From a session at the ITP Camp 2011.

TRANSCRIPT

Page 1: A Gentle Introduction to openFrameworks

a gentle introduction to openFrameworks

Becky [email protected] on slideshare

Page 2: A Gentle Introduction to openFrameworks

2 rules for this session

Page 3: A Gentle Introduction to openFrameworks

If you ever feel overwhelmed with information, feel free to say

Page 4: A Gentle Introduction to openFrameworks

If you ever feel overwhelmed with information, feel free to say

“Just tell me what to type.”

Page 5: A Gentle Introduction to openFrameworks

If you ever feel overwhelmed with information, feel free to say

“Just tell me what to type.”

If you ever want to know more or know why, feel free to say

Page 6: A Gentle Introduction to openFrameworks

If you ever feel overwhelmed with information, feel free to say

“Just tell me what to type.”

If you ever want to know more or know why, feel free to say

“I want to know more.”

Page 7: A Gentle Introduction to openFrameworks

what we will cover

Page 8: A Gentle Introduction to openFrameworks

• How is openFrameworks different from Processing?

• The structure of oF.

• Basic C++ concepts to get you going.

• Create a new openFrameworks application.

• Add your own variables and functions.

Page 9: A Gentle Introduction to openFrameworks

The magic behind Processing and Arduino

Page 10: A Gentle Introduction to openFrameworks

Code You’ve Written

Instructions for Computer?

Executable Program (e.g. .exe or .app)

Compiler +

Linker +

Loader

Page 11: A Gentle Introduction to openFrameworks

Code You’ve Written

Instructions for Computer?

Executable Program (e.g. .exe or .app)

Interactive Development

Environment (IDE)

Compiler +

Linker +

Loader

Page 12: A Gentle Introduction to openFrameworks

An IDE like Processing or Arduino includes

• text editor

•compiler and linker

•other tools to help you

Page 13: A Gentle Introduction to openFrameworks

openFrameworks does not have it’s own IDE.

On Mac you use XCode.

Page 14: A Gentle Introduction to openFrameworks

To learn oF you need to know 3 things:

• How to use an IDE

• How to write C++ code

• How to use openFrameworks libraries

Page 15: A Gentle Introduction to openFrameworks

To learn oF you need to know 3 things:

• How to use an IDE

• How to write C++ code

• How to use openFrameworks libraries

By far the easiest part.

Page 16: A Gentle Introduction to openFrameworks

oF anatomy

Page 17: A Gentle Introduction to openFrameworks

addons

openFrameworks

examples

polygonExample.xcodeproj

polygonExample

addonsExamplesmyapps

libsapps

Page 18: A Gentle Introduction to openFrameworks

Exercise

Open polygonExample and run it.

Page 19: A Gentle Introduction to openFrameworks

Why do we have 3 files?

Page 20: A Gentle Introduction to openFrameworks

main.cpp

testApp.cpp

testApp.h

Page 21: A Gentle Introduction to openFrameworks

testApp.cpp and testApp.h

Page 22: A Gentle Introduction to openFrameworks

1. Heat the oil in a large, heavy-based saucepan and fry the bacon until golden over a medium heat. Add the onions and garlic, frying until softened. Increase the heat and add the minced beef. Fry it until it has browned, breaking down any chunks of meat with a wooden spoon. Pour in the wine and boil until it has reduced in volume by about a third. Reduce the temperature and stir in the tomatoes, drained mushrooms, bay leaves, oregano, thyme and balsamic vinegar.

2. Either blitz the sun-dried tomatoes in a small blender with a little of the oil to loosen, or just finely chop before adding to the pan. Season well with salt and pepper. Cover with a lid and simmer the Bolognese sauce over a gentle heat for 1-1½ hours until it's rich and thickened, stirring occasionally. At the end of the cooking time, stir in the basil and add any extra seasoning if necessary.

3. Remove from the heat to 'settle' while you cook the spaghetti in plenty of boiling salted water (for the time stated on the packet). Drain and divide between warmed plates. Scatter a little parmesan over the spaghetti before adding a good ladleful of the Bolognese sauce, finishing with a scattering of more cheese and a twist of blackhttp://www.bbc.co.uk/food/recipes/spaghettibolognese_67868

2 tbsp olive oil or sun-dried tomato oil from the jar

6 rashers of smoked streaky bacon, chopped

2 large onions, chopped

3 garlic cloves, crushed

1kg/2¼lb lean minced beef

2 large glasses of red wine

2x400g cans chopped tomatoes

1x290g jar antipasti marinated mushrooms, drained

2 fresh or dried bay leaves

1 tsp dried oregano or a small handful of fresh leaves, chopped

1 tsp dried thyme or a small handful of fresh leaves, chopped

Drizzle balsamic vinegar

12-14 sun-dried tomato halves, in oil

Salt and freshly ground black pepper

A good handful of fresh basil leaves, torn into small pieces

800g-1kg/1¾-2¼lb dried spaghetti

Lots of freshly grated parmesan, to serve

Page 23: A Gentle Introduction to openFrameworks

1. Heat the oil in a large, heavy-based saucepan and fry the bacon until golden over a medium heat. Add the onions and garlic, frying until softened. Increase the heat and add the minced beef. Fry it until it has browned, breaking down any chunks of meat with a wooden spoon. Pour in the wine and boil until it has reduced in volume by about a third. Reduce the temperature and stir in the tomatoes, drained mushrooms, bay leaves, oregano, thyme and balsamic vinegar.

2. Either blitz the sun-dried tomatoes in a small blender with a little of the oil to loosen, or just finely chop before adding to the pan. Season well with salt and pepper. Cover with a lid and simmer the Bolognese sauce over a gentle heat for 1-1½ hours until it's rich and thickened, stirring occasionally. At the end of the cooking time, stir in the basil and add any extra seasoning if necessary.

3. Remove from the heat to 'settle' while you cook the spaghetti in plenty of boiling salted water (for the time stated on the packet). Drain and divide between warmed plates. Scatter a little parmesan over the spaghetti before adding a good ladleful of the Bolognese sauce, finishing with a scattering of more cheese and a twist of blackhttp://www.bbc.co.uk/food/recipes/spaghettibolognese_67868

2 tbsp olive oil or sun-dried tomato oil from the jar

6 rashers of smoked streaky bacon, chopped

2 large onions, chopped

3 garlic cloves, crushed

1kg/2¼lb lean minced beef

2 large glasses of red wine

2x400g cans chopped tomatoes

1x290g jar antipasti marinated mushrooms, drained

2 fresh or dried bay leaves

1 tsp dried oregano or a small handful of fresh leaves, chopped

1 tsp dried thyme or a small handful of fresh leaves, chopped

Drizzle balsamic vinegar

12-14 sun-dried tomato halves, in oil

Salt and freshly ground black pepper

A good handful of fresh basil leaves, torn into small pieces

800g-1kg/1¾-2¼lb dried spaghetti

Lots of freshly grated parmesan, to serve

Page 24: A Gentle Introduction to openFrameworks

1. Heat the oil in a large, heavy-based saucepan and fry the bacon until golden over a medium heat. Add the onions and garlic, frying until softened. Increase the heat and add the minced beef. Fry it until it has browned, breaking down any chunks of meat with a wooden spoon. Pour in the wine and boil until it has reduced in volume by about a third. Reduce the temperature and stir in the tomatoes, drained mushrooms, bay leaves, oregano, thyme and balsamic vinegar.

2. Either blitz the sun-dried tomatoes in a small blender with a little of the oil to loosen, or just finely chop before adding to the pan. Season well with salt and pepper. Cover with a lid and simmer the Bolognese sauce over a gentle heat for 1-1½ hours until it's rich and thickened, stirring occasionally. At the end of the cooking time, stir in the basil and add any extra seasoning if necessary.

3. Remove from the heat to 'settle' while you cook the spaghetti in plenty of boiling salted water (for the time stated on the packet). Drain and divide between warmed plates. Scatter a little parmesan over the spaghetti before adding a good ladleful of the Bolognese sauce, finishing with a scattering of more cheese and a twist of blackhttp://www.bbc.co.uk/food/recipes/spaghettibolognese_67868

2 tbsp olive oil or sun-dried tomato oil from the jar

6 rashers of smoked streaky bacon, chopped

2 large onions, chopped

3 garlic cloves, crushed

1kg/2¼lb lean minced beef

2 large glasses of red wine

2x400g cans chopped tomatoes

1x290g jar antipasti marinated mushrooms, drained

2 fresh or dried bay leaves

1 tsp dried oregano or a small handful of fresh leaves, chopped

1 tsp dried thyme or a small handful of fresh leaves, chopped

Drizzle balsamic vinegar

12-14 sun-dried tomato halves, in oil

Salt and freshly ground black pepper

A good handful of fresh basil leaves, torn into small pieces

800g-1kg/1¾-2¼lb dried spaghetti

Lots of freshly grated parmesan, to serve

Page 25: A Gentle Introduction to openFrameworks

1. Heat the oil in a large, heavy-based saucepan and fry the bacon until golden over a medium heat. Add the onions and garlic, frying until softened. Increase the heat and add the minced beef. Fry it until it has browned, breaking down any chunks of meat with a wooden spoon. Pour in the wine and boil until it has reduced in volume by about a third. Reduce the temperature and stir in the tomatoes, drained mushrooms, bay leaves, oregano, thyme and balsamic vinegar.

2. Either blitz the sun-dried tomatoes in a small blender with a little of the oil to loosen, or just finely chop before adding to the pan. Season well with salt and pepper. Cover with a lid and simmer the Bolognese sauce over a gentle heat for 1-1½ hours until it's rich and thickened, stirring occasionally. At the end of the cooking time, stir in the basil and add any extra seasoning if necessary.

3. Remove from the heat to 'settle' while you cook the spaghetti in plenty of boiling salted water (for the time stated on the packet). Drain and divide between warmed plates. Scatter a little parmesan over the spaghetti before adding a good ladleful of the Bolognese sauce, finishing with a scattering of more cheese and a twist of blackhttp://www.bbc.co.uk/food/recipes/spaghettibolognese_67868

2 tbsp olive oil or sun-dried tomato oil from the jar

6 rashers of smoked streaky bacon, chopped

2 large onions, chopped

3 garlic cloves, crushed

1kg/2¼lb lean minced beef

2 large glasses of red wine

2x400g cans chopped tomatoes

1x290g jar antipasti marinated mushrooms, drained

2 fresh or dried bay leaves

1 tsp dried oregano or a small handful of fresh leaves, chopped

1 tsp dried thyme or a small handful of fresh leaves, chopped

Drizzle balsamic vinegar

12-14 sun-dried tomato halves, in oil

Salt and freshly ground black pepper

A good handful of fresh basil leaves, torn into small pieces

800g-1kg/1¾-2¼lb dried spaghetti

Lots of freshly grated parmesan, to serve

We would be very irritated if there was an ingredient needed,

that wasn’t included here.

Page 26: A Gentle Introduction to openFrameworks

1. Heat the oil in a large, heavy-based saucepan and fry the bacon until golden over a medium heat. Add the onions and garlic, frying until softened. Increase the heat and add the minced beef. Fry it until it has browned, breaking down any chunks of meat with a wooden spoon. Pour in the wine and boil until it has reduced in volume by about a third. Reduce the temperature and stir in the tomatoes, drained mushrooms, bay leaves, oregano, thyme and balsamic vinegar.

2. Either blitz the sun-dried tomatoes in a small blender with a little of the oil to loosen, or just finely chop before adding to the pan. Season well with salt and pepper. Cover with a lid and simmer the Bolognese sauce over a gentle heat for 1-1½ hours until it's rich and thickened, stirring occasionally. At the end of the cooking time, stir in the basil and add any extra seasoning if necessary.

3. Remove from the heat to 'settle' while you cook the spaghetti in plenty of boiling salted water (for the time stated on the packet). Drain and divide between warmed plates. Scatter a little parmesan over the spaghetti before adding a good ladleful of the Bolognese sauce, finishing with a scattering of more cheese and a twist of blackhttp://www.bbc.co.uk/food/recipes/spaghettibolognese_67868

2 tbsp olive oil or sun-dried tomato oil from the jar

6 rashers of smoked streaky bacon, chopped

2 large onions, chopped

3 garlic cloves, crushed

1kg/2¼lb lean minced beef

2 large glasses of red wine

2x400g cans chopped tomatoes

1x290g jar antipasti marinated mushrooms, drained

2 fresh or dried bay leaves

1 tsp dried oregano or a small handful of fresh leaves, chopped

1 tsp dried thyme or a small handful of fresh leaves, chopped

Drizzle balsamic vinegar

12-14 sun-dried tomato halves, in oil

Salt and freshly ground black pepper

A good handful of fresh basil leaves, torn into small pieces

800g-1kg/1¾-2¼lb dried spaghetti

Lots of freshly grated parmesan, to serve

We would be very irritated if there was an ingredient needed,

that wasn’t included here.

The units used to describe the amount of the ingredients varies according to

the culture of the person cooking.

Page 27: A Gentle Introduction to openFrameworks

1. Heat the oil in a large, heavy-based saucepan and fry the bacon until golden over a medium heat. Add the onions and garlic, frying until softened. Increase the heat and add the minced beef. Fry it until it has browned, breaking down any chunks of meat with a wooden spoon. Pour in the wine and boil until it has reduced in volume by about a third. Reduce the temperature and stir in the tomatoes, drained mushrooms, bay leaves, oregano, thyme and balsamic vinegar.

2. Either blitz the sun-dried tomatoes in a small blender with a little of the oil to loosen, or just finely chop before adding to the pan. Season well with salt and pepper. Cover with a lid and simmer the Bolognese sauce over a gentle heat for 1-1½ hours until it's rich and thickened, stirring occasionally. At the end of the cooking time, stir in the basil and add any extra seasoning if necessary.

3. Remove from the heat to 'settle' while you cook the spaghetti in plenty of boiling salted water (for the time stated on the packet). Drain and divide between warmed plates. Scatter a little parmesan over the spaghetti before adding a good ladleful of the Bolognese sauce, finishing with a scattering of more cheese and a twist of blackhttp://www.bbc.co.uk/food/recipes/spaghettibolognese_67868

2 tbsp olive oil or sun-dried tomato oil from the jar

6 rashers of smoked streaky bacon, chopped

2 large onions, chopped

3 garlic cloves, crushed

1kg/2¼lb lean minced beef

2 large glasses of red wine

2x400g cans chopped tomatoes

1x290g jar antipasti marinated mushrooms, drained

2 fresh or dried bay leaves

1 tsp dried oregano or a small handful of fresh leaves, chopped

1 tsp dried thyme or a small handful of fresh leaves, chopped

Drizzle balsamic vinegar

12-14 sun-dried tomato halves, in oil

Salt and freshly ground black pepper

A good handful of fresh basil leaves, torn into small pieces

800g-1kg/1¾-2¼lb dried spaghetti

Lots of freshly grated parmesan, to serve

We would be very irritated if there was an ingredient needed,

that wasn’t included here.

It’s easier to follow the directions when you don’t have to list the amounts of

ingredients within the directions.

The units used to describe the amount of the ingredients varies according to

the culture of the person cooking.

Page 28: A Gentle Introduction to openFrameworks

float x;float y;float width;float height;

x = 150;y = 100;width = 90;height = 80;

ellipse(x, y, width, height);

Processing

Page 29: A Gentle Introduction to openFrameworks

float x;float y;float width;float height;

x = 150;y = 100;width = 90;height = 80;

ellipse(x, y, width, height);

ingredients or variables

Processing

Page 30: A Gentle Introduction to openFrameworks

float x;float y;float width;float height;

x = 150;y = 100;width = 90;height = 80;

ellipse(x, y, width, height);

ingredients or variables

directions or algorithm

Processing

Page 31: A Gentle Introduction to openFrameworks

float x;float y;float width;float height;

x = 150;y = 100;width = 90;height = 80;

ellipse(x, y, width, height);

ingredients or variables

directions or algorithm

data typeProcessing

Page 32: A Gentle Introduction to openFrameworks

float x;float y;float width;float height;

x = 150;y = 100;width = 90;height = 80;

ellipse(x, y, width, height);

ingredients or variables

directions or algorithm

data type variable name

Processing

Page 33: A Gentle Introduction to openFrameworks

Declaration vs InitialisationAs in a recipe, ingredients need to be listed at the top so you know what to buy.

In code, it’s so the compiler knows how much memory to reserve. This is called declaring.

Page 34: A Gentle Introduction to openFrameworks

Declaration vs InitialisationAs in a recipe, ingredients need to be listed at the top so you know what to buy.

In code, it’s so the compiler knows how much memory to reserve. This is called declaring.

int myInt;

Reserve space for an int

Page 35: A Gentle Introduction to openFrameworks

Declaration vs InitialisationAs in a recipe, ingredients need to be listed at the top so you know what to buy.

In code, it’s so the compiler knows how much memory to reserve. This is called declaring.

We don’t have to know what value will be stored in myInt right away.

We can choose a value later. This is called initialising.

int myInt;

Reserve space for an int

Page 36: A Gentle Introduction to openFrameworks

Declaration vs InitialisationAs in a recipe, ingredients need to be listed at the top so you know what to buy.

In code, it’s so the compiler knows how much memory to reserve. This is called declaring.

We don’t have to know what value will be stored in myInt right away.

We can choose a value later. This is called initialising.

int myInt;

Reserve space for an int

myInt = 15;

Store the value 15 in the space reserved for myInt

15

Page 37: A Gentle Introduction to openFrameworks

Need to declare before or at the same time as initialisation.

Page 38: A Gentle Introduction to openFrameworks

Need to declare before or at the same time as initialisation.

myInt = 3;int myInt;

Page 39: A Gentle Introduction to openFrameworks

Need to declare before or at the same time as initialisation.

myInt = 3;int myInt;

int myInt; myInt = 3;

Page 40: A Gentle Introduction to openFrameworks

Need to declare before or at the same time as initialisation.

myInt = 3;int myInt;

int myInt; myInt = 3;

Can’t use a variable before it is initialised.

Page 41: A Gentle Introduction to openFrameworks

Need to declare before or at the same time as initialisation.

myInt = 3;int myInt;

int myInt; myInt = 3;

int myInt;myInt = myInt + 7;

Can’t use a variable before it is initialised.

Page 42: A Gentle Introduction to openFrameworks

Need to declare before or at the same time as initialisation.

myInt = 3;int myInt;

int myInt; myInt = 3;

int myInt = 3;myInt = myInt + 7;

int myInt;myInt = myInt + 7;

Can’t use a variable before it is initialised.

Page 43: A Gentle Introduction to openFrameworks

To create a variable

1.Decide what the data type should be.

floatintchar

Page 44: A Gentle Introduction to openFrameworks

To create a variable

1.Decide what the data type should be.

floatintchar

to create a float type

Page 45: A Gentle Introduction to openFrameworks

To create a variable

1.Decide what the data type should be.

floatintchar

to create a float type

to create an int type

Page 46: A Gentle Introduction to openFrameworks

To create a variable

1.Decide what the data type should be.

floatintchar

to create a float type

to create an int type

to create a char type

Page 47: A Gentle Introduction to openFrameworks

To create a variable

1.Decide what the data type should be.

2.Decide on a name for your variable. Remember the rules.

floatintchar

to create a float type

to create an int type

to create a char type

Page 48: A Gentle Introduction to openFrameworks

To create a variable

1.Decide what the data type should be.

2.Decide on a name for your variable. Remember the rules.

floatintchar

to create a float type

to create an int type

to create a char type

float scale;int redValue;char finalMark;

Page 49: A Gentle Introduction to openFrameworks

To create a variable

1.Decide what the data type should be.

2.Decide on a name for your variable. Remember the rules.

floatintchar

to create a float type

to create an int type

to create a char type

float scale;int redValue;char finalMark;

you get to choose the name

Page 50: A Gentle Introduction to openFrameworks

To create a variable

1.Decide what the data type should be.

2.Decide on a name for your variable. Remember the rules.

3.If you already know what the value of that variable is, then go ahead and set the value.

floatintchar

to create a float type

to create an int type

to create a char type

float scale;int redValue;char finalMark;

you get to choose the name

Page 51: A Gentle Introduction to openFrameworks

To create a variable

1.Decide what the data type should be.

2.Decide on a name for your variable. Remember the rules.

3.If you already know what the value of that variable is, then go ahead and set the value.

floatintchar

to create a float type

to create an int type

to create a char type

float scale;int redValue;char finalMark;

float scale = 0.5;int redValue = 199;char finalMark = ‘B’;

you get to choose the name

Page 52: A Gentle Introduction to openFrameworks

To create a variable

1.Decide what the data type should be.

2.Decide on a name for your variable. Remember the rules.

3.If you already know what the value of that variable is, then go ahead and set the value.

floatintchar

to create a float type

to create an int type

to create a char type

float scale;int redValue;char finalMark;

float scale = 0.5;int redValue = 199;char finalMark = ‘B’;

if you don’t know the value yet, stop at step 2. but remember to end

each line with a ;

you get to choose the name

Page 53: A Gentle Introduction to openFrameworks

In Processing, the declarations are at the top of the file.

In openFrameworks, the declarations are in a separate file (testApp.h, the header file).

This file is included in main.cpp.

Page 54: A Gentle Introduction to openFrameworks

main functions

Page 55: A Gentle Introduction to openFrameworks

Every program has a main function.

It’s the starting point.

It’s hidden in Processing, but exposed in openFrameworks in main.cpp.

Defines:the window size

ofAppGlutWindow window;ofSetupOpenGL(&window, 1024,768, OF_WINDOW);

and your application classofRunApp( new testApp());

Page 56: A Gentle Introduction to openFrameworks

Exercise

Create a copy of emptyExample in your myapps folder.

Rename the folder and .xcodeproj file.

Open the project.

Rename the target.

Make sure it builds and runs.

Page 57: A Gentle Introduction to openFrameworks

openFrameworks

Page 58: A Gentle Introduction to openFrameworks

• Really similar functionality as Processing.

• Fully documented here:

• http://www.openframeworks.cc/documentation

Page 59: A Gentle Introduction to openFrameworks

Exercise

Open your new empty project.

Create a purple circle in the center of the window.

Move the center of the circle to where you click within the window.

Page 60: A Gentle Introduction to openFrameworks

• Speed

• Accessibility of low level information

• Debugger

• C++

• Version control

Why do I use oF over Processing?

Page 61: A Gentle Introduction to openFrameworks

what is OOP? it sounds sticky

Page 62: A Gentle Introduction to openFrameworks

myApp

oscHandler textButton

myApp.cpp myApp.h

main.cpp

oscHandler.cpp

oscHandler.h

textButton.cpp

textButton.h

Page 63: A Gentle Introduction to openFrameworks

oscHandler textButton

oscHandler.cpp

oscHandler.h

textButton.cpp

textButton.h

myOtherApp

myOtherApp.cpp myOtherApp.h

main.cpp