Write a CPlusPlus DLL
The CPlusPlus OP(s) allow you to load your own C++ code that has been compiled into a .dll. You can use this node to create custom filters, output to some custom file format or device, or to bring data in from some custom device or file format. Depending on the type of OP the input/output, behavior and function names will be different, but the general idea is the same. Although these OPs are not the same as a full SDK, they provide much of the same functionality.
Touch defines a base C++ class that you will inherit from to you create your own class. There are some pure-virtual functions you are required to override, while there are others that will do some default behavior of you don't provide an overridden method. Data is passed in and out of the functions using other simple classes which hold the information.
To get initialize the .dll and create an instance of the class there are 3 C functions you are required to specify. The first one will tell Touch which version of the API you are running (by returning a constant which you can see in the header file). The other two will create (using
new) and destroy (using
delete) an instance of the class when Touch asks them to. A single instance of the class will get created for each OP that is using the .dll.
You can find code to get started making the .dll in the <TouchInstallDirectory>/touch/CPlusPlus/<OPFamily> directory. There will be a base class defined in a header file (for example TOP_CPlusPlusBase.h) which should not be edited. You will make a child of this base class. An example child class has already been made in the *Example.cpp and *Example.h files. Much of the information you will need to program a .dll will be in the comments of these files, as well as the base class header file.
General Work flow
In general when the CPlusPlus OP cooks it will call some functions in your class which are asking some questions (for example, if the node should cook every frame). It will then call the
execute() where your class should do the actual work.
The sample was created and compiled using Visual Studio 2005. If you use a different compiler you need to ensure that the memory layout of the class members is identical to what Visual Studio 2005 uses.
You can attach the Visual Studio debugger to TouchDesigner.exe when it's running and put breakpoints in your .dll code. When your code is executing the breakpoints will be hit and you can debug as you normally would. This is also a good way to explore all the data structures TouchDesigner passes in and out of the functions.
Info CHOP and Info DAT
All of the CPlusPlus OPs support outputting data through the Info CHOP and Info DAT. There are functions where you can specify how much data you want to output, and then others where you specify the actual data you want to output.
Using other libraries
If you wish to use OpenCV, whose .dlls are included as part of our installer, you should build with the these header files and libraries: Media:TD077_OpenCV.zip