← Back
Before you start
Java → C++ reference table for a convenient workflow
A quick cheat-sheet for porting a Processing (Java) sketch to Umfeld (C++).
This is the atomic, syntax-level reference. For conceptual differences and rationale, read the Umfeld and Processing article.
Umfeld names and signatures below are checked against the public
Umfeld.h,
UmfeldCallbacks.h,
UmfeldFunctions.h,
UmfeldFunctionsAdditional.h,
UmfeldFunctionsGraphics.h, and
PImage.h headers.
The headers are authoritative if the API changes.
How to read each section: the left column is what you would type in Processing, the middle column is the Umfeld (C++) equivalent, the right column is a one-line note explaining the change or a gotcha.
Sketch structure
| Processing (Java) | Umfeld (C++) | Notes |
|---|---|---|
void setup() { size(800, 600); } |
void settings() { size(800, 600); } |
size() lives in settings(), not setup() |
void setup() { ... } |
void setup() { ... } |
Same role |
void draw() { ... } |
void draw() { ... } |
Same role |
void mousePressed() { ... } |
void mousePressed() { ... } |
Callback, unchanged |
void keyPressed() { ... } |
void keyPressed() { ... } |
Callback, unchanged |
void mouseWheel(MouseEvent e) |
void mouseWheel(float x, float y) |
Different signature |
void windowResized() |
void windowResized(int w, int h) |
Receives new size as parameters |
| n/a | void update() |
Umfeld-only, runs before draw() |
| n/a | void post() |
Umfeld-only, runs after draw() |
| n/a | void shutdown() |
Umfeld-only, runs on exit |
| n/a | void dropped(const char* path) |
Umfeld-only, file dropped on window |
Globals you read every frame
| Processing | Umfeld | Notes |
|---|---|---|
width, height |
width, height |
float — watch out for width % 2 errors |
frameCount |
frameCount |
int |
frameRate(60) |
setFrameRate(60) or set_frame_rate(60) |
frameRate is the measured-rate variable; use either setter |
mouseX, mouseY |
mouseX, mouseY |
float |
pmouseX, pmouseY |
pmouseX, pmouseY |
|
mouseButton |
mouseButton |
int |
mousePressed |
isMousePressed |
Renamed — collided with callback name |
key |
key |
int |
keyCode |
keyCode |
int |
keyPressed |
isKeyPressed |
Renamed — collided with callback name |
displayWidth |
displayWidth (display_width) |
int; snake-case name is also public |
displayHeight |
displayHeight (display_height) |
int; snake-case name is also public |
Colour
| Processing | Umfeld | Notes |
|---|---|---|
color c = color(255, 100, 0); |
color_t c = color(255, 100, 0); |
Type renamed to color_t |
fill(c); |
fill(c); |
Same |
fill(0.5) |
fill(0.5f) |
Add f suffix to avoid double/float mix |
| n/a | fill_color(0xFF44FF88); |
Explicit packed ABGR (0xAABBGGRR) |
colorMode(RGB, 1.0) |
colorMode(RGB, 1.0f) |
Warning: this breaks standard fill(255) |
stroke(c), background(c) |
same | |
lerpColor(a, b, t) |
lerpColor(a, b, t) |
Console output
| Processing | Umfeld | Notes |
|---|---|---|
println("hi") |
println("hi") |
Same |
println("x = " + mouseX) |
println("x = ", mouseX) |
Comma, not + |
print(x) |
print(x) |
|
| n/a | console("hi", x) |
Umfeld-only, adds timestamp |
| n/a | std::string s = str("x = ", mouseX); |
Build mixed-type strings via str() |
Keywords and constants
| Processing | Umfeld | Notes |
|---|---|---|
final |
const |
|
null |
nullptr |
|
import |
#include |
#include "Umfeld.h" |
color |
color_t |
Type rename |
Math.PI |
PI |
Umfeld exposes Processing-style constants |
Math.E |
std::exp(1.0f) |
Standard C++17 (<cmath>); Umfeld does not expose an E constant |
Strings
| Processing (Java) | Umfeld (C++) | Notes |
|---|---|---|
String s = "hi"; |
std::string s = "hi"; |
Always prefer std::string |
s.length() |
s.length() or s.size() |
|
s + "!" |
s + "!" |
Works only when at least one side is std::string |
s.equals(t) / s == t |
s == t |
Works for std::string |
Integer.parseInt(s) |
std::stoi(s) |
Throws if not parseable |
Float.parseFloat(s) |
std::stof(s) |
|
String.valueOf(x) |
std::to_string(x) |
|
mixed-type concat: "a" + 1 |
str("a", 1) |
Umfeld helper |
Numbers and math
| Processing | Umfeld | Notes |
|---|---|---|
float x = 1.0; |
float x = 1.0f; |
f suffix avoids double promotion |
int i = (int) 3.7; |
int i = (int) 3.7f; |
Same syntax |
random(100) |
random(100) |
Warning: not thread-safe. Use std::mt19937 in threads |
noise(x, y) |
noise(x, y) |
Public overloads accept one, two, or three coordinates |
map(v, a, b, c, d) |
map(v, a, b, c, d) |
All args same float type or cast |
constrain(v, lo, hi) |
constrain(v, lo, hi) |
Same rule about types |
Integer.MAX_VALUE |
INT_MAX |
from <climits> |
Float.MAX_VALUE |
FLT_MAX |
from <cfloat> |
Arrays and collections
| Processing (Java) | Umfeld (C++) | Notes |
|---|---|---|
int[] a = new int[10]; |
std::vector<int> a(10); |
Prefer std::vector over raw arrays |
int[] a = {1, 2, 3}; |
std::vector<int> a = {1, 2, 3}; |
|
a.length |
a.size() |
|
a[i] |
a[i] or a.at(i) |
.at(i) adds bounds check |
ArrayList<Foo> list; |
std::vector<Foo> list; |
|
list.add(x) |
list.push_back(x) |
|
list.size() |
list.size() |
|
list.get(i) |
list[i] |
|
for (Foo f : list) |
for (auto& f : list) |
auto& avoids copies |
HashMap<K,V> m; |
std::unordered_map<K,V> m; |
Classes and objects
| Processing (Java) | Umfeld (C++) | Notes |
|---|---|---|
class Foo { int x; } |
class Foo { public: int x; }; |
Trailing ; required; everything is private by default |
new Foo() |
Foo f; (stack) or new Foo() (heap) |
Prefer stack; let scope manage lifetime |
Foo f = new Foo(); |
Foo f; |
Stack-allocated object |
null |
nullptr |
|
f.x |
f.x |
When f is an instance |
| n/a | f->x |
When f is a pointer |
this.x |
this->x or just x |
|
extends Bar |
: public Bar |
Public inheritance |
super.foo() |
Bar::foo() |
|
| automatic GC | RAII / delete / std::unique_ptr |
Stack objects clean up automatically |
Files and IO
| Processing (Java) | Umfeld (C++) | Notes |
|---|---|---|
loadStrings("f.txt") |
auto lines = loadStrings("f.txt"); |
Returns std::vector<std::string> (unlike Processing’s String[]) |
saveStrings(...) |
saveStrings("f.txt", lines) |
Takes a std::vector<std::string> |
loadBytes("f.bin") |
auto bytes = loadBytes("f.bin"); |
Returns std::vector<uint8_t> |
saveBytes(...) |
saveBytes("f.bin", bytes) |
Takes std::vector<uint8_t> |
loadImage("p.jpg") |
PImage* img = loadImage("p.jpg"); |
Returns a pointer — use -> for methods |
loadFont("f.ttf") |
PFont* f = loadFont("f.ttf", 24); |
Required before text() will draw anything |
loadShader(fragmentFile) |
PShader* s = loadShader(vertexCode, fragmentCode); |
Umfeld accepts shader source strings; caller owns the returned pointer |
Drawing
| Processing | Umfeld | Notes |
|---|---|---|
background(0) |
background(0) |
|
fill(255, 80, 40) |
fill(255, 80, 40) |
|
stroke(...) |
stroke(...) |
|
noFill() / noStroke() |
noFill() / noStroke() |
|
line(x1, y1, x2, y2) |
line(x1, y1, x2, y2) |
|
rect(x, y, w, h) |
rect(x, y, w, h) |
|
ellipse(x, y, w, h) |
ellipse(x, y, w, h) |
|
circle(x, y, d) |
circle(x, y, d) |
|
triangle(...) |
triangle(...) |
|
beginShape() / vertex / endShape() |
same | |
image(img, sx, sy, sw, sh, dx, dy, dw, dh) |
copy(img, sx, sy, sw, sh, dx, dy, dw, dh) |
Use copy() for source-region drawing |
img.copy(...) |
img->copy(...) |
No arguments returns an owned deep copy; arguments copy/scale a region |
img.set(x, y, value) |
img->set(x, y, value) |
value may be a color or PImage* |
img.blend(...) |
img->blend(...) |
CPU compositing supports every BlendMode |
img.filter(GRAY) |
img->filter(GRAY) |
Also threshold, posterize, blur, erode, dilate, and others |
img.mask(mask) |
img->mask(mask) |
Mask dimensions must match the image |
translate(x, y) |
translate(x, y) |
(0,0) is Top-Left (Y-DOWN) |
rotate(a) / scale(s) |
rotate(a) / scale(s) |
rotate() takes radians, not degrees |
pushMatrix() / popMatrix() |
pushMatrix() / popMatrix() |
Pair calls so later transforms restore the expected state |
Build and project layout
| Processing | Umfeld | Notes |
|---|---|---|
| Open in PDE, hit play | cmake -B build && cmake --build build && ./build/myapp |
One-liner per sketch |
MySketch/MySketch.pde |
MySketch/application.cpp + MySketch/CMakeLists.txt |
Flat layout per project |
import g4p_controls.*; |
add_subdirectory(<path>) + target_link_libraries(...) in CMake |
See umfeld-libraries |
data folder data/ next to sketch |
data folder next to executable | Look up actual lookup paths |
A few habits that travel well:
- Declare variable types explicitly — C++ will not infer them across scopes the way you might expect.
- Class definitions end with a semicolon
;. - Prefer
std::vectorover raw arrays; it behaves like Java’sArrayList.
Keep this page open in a tab while you port your first sketch.