Openframeworks For Mac
The first few lectures of term will cover using, a framework for creative coding that is similar to Processing but is based on C. This means that OpenFrameworks is faster than Processing and is able to access a lot of library functions written in C. It is often used for computer vision based art works, which are both computationally intensive an use a lot of pre-existing libraries. Because openFrameworks is very similar to processing, you should find it pretty easy to get up and running. Underneath the surface, however, it is cold, hard C.
You can do a great many things in openFrameworks without worrying too much about this though. Just dive in. You will probably find this useful: If you are looking for an introduction to C you can also try: and check out others on the There are millions of books on C, is a pretty good one if you already know how to program. What follows is an introduction to C using openFrameworks.
It’s best to treat these as notes, rather than things you have to learn straight away and remember. This will take you through some of the differences between java and C (and reasons why C is more complex after a while). There are many examples of this but I’ll start with the most basic, how C is compiled. In the labs we will be using XCode on a Mac, but if you want to use windows you can use either codeblocks or visual studio. You can get the free version here. You can also get the most recent version of Visual Studio via MSDNN if you are a goldsmiths computing student, via the departmental intranet: What happens when you Compile C Code?
Computers cannot directly understand programming languages like C and Java, the must first be converted into the underlying machine language, a process called compiling. In C this is direct, code is converted directly into machine code: The result is native machine code which is very fast, but is different between different types of machine. You need to recompile C code if you want to run it on a PC or a Mac (OK, my argument doesn’t make sense any more because both are intel based and therefore have the same machine code, but you still have to recompile them, but for other reasons). Java is completely cross platform, you compile it once and can run it on any machine. That is because it compiles into a java virtual machine code, called bytecode, which is then interpreted at run time into machine code.
This makes life easier but is slower because it is having to translate bytecode to machine code at run time. There are lots of other ways in which C is fast but harder to use, I will cover some in later lectures. Back to compiling C. The picture is more complex. Firstly, there is something called a pre-processor, which does some text substitution tasks, before compilation. I will discuss it later.
Openframeworks Mac Windows
More importantly, programs are made up of multiple files. Each of these are compiled separately, and have to be combined together by a piece of software called a linker to create the final program. There are two types of file in C.cpp files contain code. These are the files that get compiled and eventually linked.
However, if they are compiled separately and a class in one cpp file uses a class that is defined in another cpp file, how do they know about each other? This is done through.h files (header files). These contain definitions of classes but no actual code. The.h files are included in the cpp files using the following code. #include 'boid.h' This is very similar to an import statement in java (or Processing), but works a bit differently. It is done by the pre-processor and works in a really simple way.
The preprocessor literally just copies the whole text of boid.h into the cpp file replacing the #include statement. Openframeworks Openframeworks is a library of code that provides graphics and sound functionality in much the same way Processing does. Unlike Processing, it does not provide its own development environment, which mean to edit code you will need to you a development environment specific to your operating systems:. on windows or linux. on windows. on a mac Many of the specifics of setting up a project will depend on which you use.
I will give an overview of the basic process with examples in xcode. You can get more details from the openframeworks wiki: You can also use Eleanor Dare’s slides on openframeworks using codeblock.
Setting up openframeworks The first thing you need to do is download openframeworks from their site: Make sure you download the appropriate distribution for your operating system and development environment. Also make sure you download the FAT version which include addons that we will use. When you unzip it you will get a folder containing openframeworks, you don’t need to install it.
The directory contains a bunch of examples in the apps-examples folder. Open any of these and you should see a project file for your development environment. For example, on a mac the graphicsExample folder contains a file graphicsExample.xcodeproj. Open this file and it will fire up your development environment. On a mac you will get xcode: click on the “build and run” button at the top of the screen and xcode will compile the example (will take a bit of time) and then run it. If there are errors compiling it, check the openframework documentation.
The easiest way to start a new project is to just copy an exiting project folder and rename the folder and project file. You can then open it edit it in your development environment. It will give you the basis on which to build your own code. Another thing you might want to do is to use an addon in your project.
Again the easiest way of doing this is to copy an example that uses that addon. If you want to include an addon in an existing project you need to add the folder of that addon to your project in your developement environment. All the addons are stored in the folder addons in the main openframeworks folder. The openframeworks startup guide for your development environment should explain how to include an addon. I’ll explain it for xcode, the others are similar. First you need to create a new folder (called a group) for addons. You need to right click (or ctrl click) on the project name at the top of the folder listing on the left of the screen, do new-group: Then you need to rename that group “addons”: You then need to add the files to it.
Right (or ctrl) click on addons and choose Add-Existing Files You then find the folder containing the addon you want and add it to the group: To actually use the addon you will also have to include the header (.h) files from that addon in your files (see below). Openframeworks code The openframeworks example apps consist of 2 code (.cpp) files and 1 header (.h) file. If they define extra classes there will be more files, but more on that next week. I will begin by going through the three files in the example I went through in class.
Openframeworks Mac カメラ
The first file is Main.cpp. This is the code the starts the app running. Every C program has to have a function called main, which is where the program starts running. In the case of an openframeworks app main sets up a window, creates the app and runs it. You generally don’t change this file at all (unless you want to rename your app something different from testApp) so I won’t go through it in detail.