ofxKinect Library - Draw Rectangles from update

Hey all,

I’m only a few months in to using openFrameworks and was pretty decent with Processing, but since update and draw are two separate functions I’m having a hard time understanding how to go through a 2D pixel array loop and draw rectangles.

Essentially I’m using a ofxKinect to read the depth data from a kinect. If anything is within a certain threshold of depth I want my program to read the RGB color and draw a 4x4 rectangle. The end effect should look like the user gets pixelated as they get closer to the camera.

I know how to read the depth data in the update() loop and set an ofImage titled curFrame to the latest RGB value, but I’m getting tripped up on how to get to the draw() loop to draw the rectangles that I want. See below for my .cpp code:

#include “testApp.h”

void testApp::setup() {
kinect.setRegistration(true);// enable depth->video image calibration

colorImg.allocate(kinect.width, kinect.height);
grayImage.allocate(kinect.width, kinect.height);


angle = 17;

// start from the front
bDrawPointCloud = false;

curFrame.allocate(kinect.width, kinect.height, OF_IMAGE_COLOR);
scale = 4;
cols = ofGetWindowWidth()/scale;
rows = ofGetWindowHeight()/scale;

void testApp::update() {
ofBackground(0, 0, 0);

if(kinect.isFrameNew()) {

ofPixels& depthPixels = kinect.getDepthPixelsRef();
ofPixels& colorPixels = kinect.getPixelsRef();

for (int i= 0; i < 640; i++) {
for (int j = 0; j < 480; j++) {

color = colorPixels.getColor(i, j);
depth = depthPixels.getColor(i, j);

if(depth.getBrightness() < mouseX){
curFrame.setColor(i, j, color);



void testApp::draw() {
curFrame.draw(0,0,640,480);//modified image

Any help would be appreciated.

You can could use an fbo, or you could pass a couple textures to a shader