I’ve been building a plugin for the Processing 4 IDE called C++ Mode. It lets you write sketches in C++, using the same API you’re used to. setup(), draw(), background(), mouseX, fill(), all still there.
C++ is rough to start with if you just want to draw something on screen. You need a build system, a window, an OpenGL context, and a pile of setup code before anything shows up. C++ Mode handles that part. Type this:
ellipse(300, 300, 50, 50);
Hit Run, see a circle.
If you already know Processing, you already know how to use this. Start with sketches that look like the Java version, then bring in structs, vectors, pointers, templates, whenever you want.
Its been quite awhile since I did any C++ programming so I was interested in trying it so I started with this on
Processing 4.5.6
iMac Intel processor
osx 15.7.6
// Full C++ STL is available without any #include.
// See https://processing-cpp.github.io/libraries
// Full C++ STL is available without any #include.
// See https://processing-cpp.github.io/libraries
void setup() {
// put your setup code here, to run once:
size(640, 360);
}
void draw() {
background(20);
ellipse(mouseX, mouseY, 40,40);
}
and got the following output, not sure if I missed doing something I should have
In file included from /Users/peter/Documents/Processing 3/modes/CppMode/src/Processing.cpp:48:
/Users/peter/Documents/Processing 3/modes/CppMode/src/stb_image_write.h:776:13: warning: 'sprintf' is deprecated: This
function is provided for compatibility reasons only. Due to security concerns inherent in the design of sprintf(3),
it is highly recommended that you use snprintf(3) instead. [-Wdeprecated-declarations]
776 | len = sprintf(buffer, "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x);
| ^
/Applications/Programming/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_
stdio.h:278:1: note: 'sprintf' has been explicitly marked deprecated here
278 | __deprecated_msg("This function is provided for compatibility reasons only. Due to security concerns inherent
in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead.")
| ^
/Applications/Programming/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/s
ys/cdefs.h:227:48: note: expanded from macro '__deprecated_msg'
227 | #define __deprecated_msg(_msg) __attribute__((__deprecated__(_msg)))
| ^
/Users/peter/Documents/Processing 3/modes/CppMode/src/Processing.cpp:2213:27: warning: result of comparison of constant
128 with expression of type 'char' is always false [-Wtautological-constant-out-of-range-compare]
2213 | if (ch < 32 || ch >= 128) continue;
| ~~ ^ ~~~
2 warnings generated.
In file included from
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_15940562549130875835temp/Sketch_run.cpp:49:
/Users/peter/Documents/Processing 3/modes/CppMode/src/Processing_api.h:103:24: error: no type named 'string' in
namespace 'std'; did you mean simply 'string'?
103 | inline void text(const std::string& s,float x,float y) { if(::g_papplet) ::g_papplet->text(s,x,y); }
| ^~~~~~~~~~~
| string
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_15940562549130875835temp/Sketch_run.cpp:2:31: note:
'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
In file included from
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_15940562549130875835temp/Sketch_run.cpp:49:
/Users/peter/Documents/Processing 3/modes/CppMode/src/Processing_api.h:109:30: error: no type named 'string' in
namespace 'std'; did you mean simply 'string'?
109 | inline float textWidth(const std::string& s) { return ::g_papplet ? ::g_papplet->textWidth(s) : 0; }
| ^~~~~~~~~~~
| string
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_15940562549130875835temp/Sketch_run.cpp:2:31: note:
'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
In file included from
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_15940562549130875835temp/Sketch_run.cpp:49:
/Users/peter/Documents/Processing 3/modes/CppMode/src/Processing_api.h:112:24: error: no type named 'string' in
namespace 'std'; did you mean simply 'string'?
112 | inline void save(const std::string& f="") { if(::g_papplet) ::g_papplet->save(f); }
| ^~~~~~~~~~~
| string
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_15940562549130875835temp/Sketch_run.cpp:2:31: note:
'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
In file included from
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_15940562549130875835temp/Sketch_run.cpp:49:
/Users/peter/Documents/Processing 3/modes/CppMode/src/Processing_api.h:112:37: error: reference to type 'const int'
could not bind to an lvalue of type 'const char[1]'
112 | inline void save(const std::string& f="") { if(::g_papplet) ::g_papplet->save(f); }
| ^ ~~
/Users/peter/Documents/Processing 3/modes/CppMode/src/Processing_api.h:112:37: note: passing argument to parameter 'f'
here
/Users/peter/Documents/Processing 3/modes/CppMode/src/Processing_api.h:113:29: error: no type named 'string' in
namespace 'std'; did you mean simply 'string'?
113 | inline void saveFrame(const std::string& f="frame-####.png"){ if(::g_papplet) ::g_papplet->saveFrame(f); }
| ^~~~~~~~~~~
| string
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_15940562549130875835temp/Sketch_run.cpp:2:31: note:
'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
In file included from
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_15940562549130875835temp/Sketch_run.cpp:49:
/Users/peter/Documents/Processing 3/modes/CppMode/src/Processing_api.h:113:42: error: reference to type 'const int'
could not bind to an lvalue of type 'const char[15]'
113 | inline void saveFrame(const std::string& f="frame-####.png"){ if(::g_papplet) ::g_papplet->saveFrame(f); }
| ^ ~~~~~~~~~~~~~~~~
/Users/peter/Documents/Processing 3/modes/CppMode/src/Processing_api.h:113:42: note: passing argument to parameter 'f'
here
/Users/peter/Documents/Processing 3/modes/CppMode/src/Processing_api.h:114:32: error: no type named 'string' in
namespace 'std'; did you mean simply 'string'?
114 | inline PImage* loadImage(const std::string& p) { return ::g_papplet ? ::g_papplet->loadImage(p) :
nullptr; }
| ^~~~~~~~~~~
| string
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_15940562549130875835temp/Sketch_run.cpp:2:31: note:
'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
In file included from
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_15940562549130875835temp/Sketch_run.cpp:49:
/Users/peter/Documents/Processing 3/modes/CppMode/src/Processing_api.h:162:31: error: no type named 'string' in
namespace 'std'; did you mean simply 'string'?
162 | inline void windowTitle(const std::string& t) { if(::g_papplet) ::g_papplet->windowTitle(t); }
| ^~~~~~~~~~~
| string
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_15940562549130875835temp/Sketch_run.cpp:2:31: note:
'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
In file included from
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_15940562549130875835temp/Sketch_run.cpp:49:
/Users/peter/Documents/Processing 3/modes/CppMode/src/Processing_api.h:163:29: error: no type named 'string' in
namespace 'std'; did you mean simply 'string'?
163 | inline PFont loadFont(const std::string& f) { static PFont d; return ::g_papplet ?
::g_papplet->loadFont(f) : d; }
| ^~~~~~~~~~~
| string
/var/folders/m1/0yj_65bx2_l9x55jn9b8q0600000gn/T/processing/cpp_test_15940562549130875835temp/Sketch_run.cpp:2:31: note:
'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
9 errors generated.
I ran the following source code per the instructions and got an error message similar to Quark. I also had to use Homebrew to install ‘glew’ and also updated ‘glfw’ initially.
In file included from
/var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo8311304946160243556temp/Sketch_run.cpp:1:
/Users/xxxxx/Documents/Processing/modes/CppMode/src/Processing.h:378:48: warning: implicit conversion from 'int' to
'float' changes value from 2147483647 to 2147483648 [-Wimplicit-const-int-float-conversion]
378 | float a = static_cast(rand()) / RAND_MAX * 6.28318f;
| ~ ^~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_stdlib.h:124
:18: note: expanded from macro 'RAND_MAX'
124 | #define RAND_MAX 0x7fffffff
| ^~~~~~~~~~
In file included from
/var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo8311304946160243556temp/Sketch_run.cpp:1:
/Users/xxxx/Documents/Processing/modes/CppMode/src/Processing.h:382:48: warning: implicit conversion from 'int' to
'float' changes value from 2147483647 to 2147483648 [-Wimplicit-const-int-float-conversion]
382 | float t = static_cast(rand()) / RAND_MAX * 6.28318f;
| ~ ^~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_stdlib.h:124
:18: note: expanded from macro 'RAND_MAX'
124 | #define RAND_MAX 0x7fffffff
| ^~~~~~~~~~
In file included from
/var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo8311304946160243556temp/Sketch_run.cpp:1:
/Users/xxxxx/Documents/Processing/modes/CppMode/src/Processing.h:383:67: warning: implicit conversion from 'int' to
'float' changes value from 2147483647 to 2147483648 [-Wimplicit-const-int-float-conversion]
383 | float p = ::std::acos(2.0f * static_cast(rand()) / RAND_MAX - 1.0f);
| ~ ^~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_stdlib.h:124
:18: note: expanded from macro 'RAND_MAX'
124 | #define RAND_MAX 0x7fffffff
| ^~~~~~~~~~
In file included from
/var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo8311304946160243556temp/Sketch_run.cpp:49:
/Users/xxxxx/Documents/Processing/modes/CppMode/src/Processing_api.h:103:24: error: no type named 'string' in namespace
'std'; did you mean simply 'string'?
103 | inline void text(const std::string& s,float x,float y) { if(::g_papplet) ::g_papplet->text(s,x,y); }
| ^~~~~~~~~~~
| string
/var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo8311304946160243556temp/Sketch_run.cpp:2:31:
note: 'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
In file included from
/var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo8311304946160243556temp/Sketch_run.cpp:49:
/Users/xxxxx/Documents/Processing/modes/CppMode/src/Processing_api.h:109:30: error: no type named 'string' in namespace
'std'; did you mean simply 'string'?
109 | inline float textWidth(const std::string& s) { return ::g_papplet ? ::g_papplet->textWidth(s) : 0; }
| ^~~~~~~~~~~
| string
/var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo8311304946160243556temp/Sketch_run.cpp:2:31:
note: 'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
In file included from
/var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo8311304946160243556temp/Sketch_run.cpp:49:
/Users/xxxxx/Documents/Processing/modes/CppMode/src/Processing_api.h:112:24: error: no type named 'string' in namespace
'std'; did you mean simply 'string'?
112 | inline void save(const std::string& f="") { if(::g_papplet) ::g_papplet->save(f); }
| ^~~~~~~~~~~
| string
/var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo8311304946160243556temp/Sketch_run.cpp:2:31:
note: 'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
In file included from
/var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo8311304946160243556temp/Sketch_run.cpp:49:
/Users/xxxxx/Documents/Processing/modes/CppMode/src/Processing_api.h:112:37: error: reference to type 'const int' could
not bind to an lvalue of type 'const char[1]'
112 | inline void save(const std::string& f="") { if(::g_papplet) ::g_papplet->save(f); }
| ^ ~~
/Users/xxxxx/Documents/Processing/modes/CppMode/src/Processing_api.h:112:37: note: passing argument to parameter 'f'
here
/Users/xxxxx/Documents/Processing/modes/CppMode/src/Processing_api.h:113:29: error: no type named 'string' in namespace
'std'; did you mean simply 'string'?
113 | inline void saveFrame(const std::string& f="frame-####.png"){ if(::g_papplet) ::g_papplet->saveFrame(f); }
| ^~~~~~~~~~~
| string
/var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo8311304946160243556temp/Sketch_run.cpp:2:31:
note: 'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
In file included from
/var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo8311304946160243556temp/Sketch_run.cpp:49:
/Users/xxxxx/Documents/Processing/modes/CppMode/src/Processing_api.h:113:42: error: reference to type 'const int' could
not bind to an lvalue of type 'const char[15]'
113 | inline void saveFrame(const std::string& f="frame-####.png"){ if(::g_papplet) ::g_papplet->saveFrame(f); }
| ^ ~~~~~~~~~~~~~~~~
/Users/xxxxx/Documents/Processing/modes/CppMode/src/Processing_api.h:113:42: note: passing argument to parameter 'f'
here
/Users/xxxxx/Documents/Processing/modes/CppMode/src/Processing_api.h:114:32: error: no type named 'string' in namespace
'std'; did you mean simply 'string'?
114 | inline PImage* loadImage(const std::string& p) { return ::g_papplet ? ::g_papplet->loadImage(p) :
nullptr; }
| ^~~~~~~~~~~
| string
/var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo8311304946160243556temp/Sketch_run.cpp:2:31:
note: 'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
In file included from
/var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo8311304946160243556temp/Sketch_run.cpp:49:
/Users/xxxxx/Documents/Processing/modes/CppMode/src/Processing_api.h:162:31: error: no type named 'string' in namespace
'std'; did you mean simply 'string'?
162 | inline void windowTitle(const std::string& t) { if(::g_papplet) ::g_papplet->windowTitle(t); }
| ^~~~~~~~~~~
| string
/var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo8311304946160243556temp/Sketch_run.cpp:2:31:
note: 'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
In file included from
/var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo8311304946160243556temp/Sketch_run.cpp:49:
/Users/xxxxx/Documents/Processing/modes/CppMode/src/Processing_api.h:163:29: error: no type named 'string' in namespace
'std'; did you mean simply 'string'?
163 | inline PFont loadFont(const std::string& f) { static PFont d; return ::g_papplet ?
::g_papplet->loadFont(f) : d; }
| ^~~~~~~~~~~
| string
/var/folders/x2/hwxvmv9s6t16_tkw9tgmbp040000gn/T/processing/cplusplus_demo8311304946160243556temp/Sketch_run.cpp:2:31:
note: 'string' declared here
2 | using std::vector; using std::string; using std::wstring;
| ^
3 warnings and 9 errors generated.