Move unchanging geometry, grids, and text into a PGraphics offscreen buffer during setup, then composite it with a single image() call each frame. This guide covers buffer creation, renderer matching, resize handling, memory limits, and verification steps.
PGraphics lets you cache static drawing layers in an off-screen buffer, then composite them each frame with a single image() call. This guide shows a complete worked example, explains memory limits, and lists the common mistakes that cause crashes or visual artifacts.
Learn how to use Processing’s PGraphics buffer for clean off‑screen rendering, compositing, and image export. A step‑by‑step example shows gradient generation, memory tips, and trade‑offs.
When a Processing sketch stutters because static elements are redrawn every frame, PGraphics offers an off-screen buffer you can composite with a single image() call. Here is how the pattern works, a concrete example, and the memory and renderer trade-offs to check.
Use PGraphics to draw static content once into an off-screen buffer and blit it each frame with image(), turning expensive per-frame redraws into a single cheap texture copy.
Use Processing's PGraphics class to draw offscreen: create the buffer once, wrap drawing in beginDraw/endDraw, composite with image(), and export with pg.save().