Each frame the program tries to get a fresh image. For a camera this comes from a queue fed by a background thread. For a file it is read on the spot. The image is flipped vertically so texture coordinates match the shader. If a new frame exists it updates the OpenGL texture named camera_texture. If the texture cache is active and the current shader name contains the word cache the program occasionally pushes the new frame into the frame cache and updates the four cache textures as a set so your fragment code can read multiple time slices.
The program binds the offscreen framebuffer and clears it. It selects the current shader and updates uniforms for time, mouse position, mouse click start, and resolution. Time can come from the system clock or from audio amplitude when audio is enabled. Mouse is reported as a four component vector where the first two components are the current cursor position and the last two are the point where a drag began.
In 3D mode the program sets up a view and projection matrix, computes a camera direction based on keys, and draws the model with the live video bound to a sampler named samp. In 2D mode the program draws the sprite that covers the window with the live video. Either way the fragment shader runs on what is drawn.
If recording is active or if you pressed the snapshot key the program reads the offscreen texture back into system memory, flips rows so the image is right side up, queues the pixel block for the writer thread, then draws the offscreen result to the window. The window title is updated with progress and the code sleeps a little in file mode to approximate the original fps.