diff options
Diffstat (limited to 'src/testApp.cpp')
| -rw-r--r-- | src/testApp.cpp | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/src/testApp.cpp b/src/testApp.cpp index 0e6e0d5..81b77e2 100644 --- a/src/testApp.cpp +++ b/src/testApp.cpp @@ -41,11 +41,41 @@ void testApp::setup(){ light=true; + camWidth = 320; // try to grab at this size. + camHeight = 240; + + vidGrabber.setVerbose(true); + vidGrabber.listDevices(); + + + vidGrabber.setDeviceID(0); + vidGrabber.initGrabber(camWidth,camHeight); + //printf("asked for 320 by 240 - actual size is %i by %i\n", vidGrabber.width, vidGrabber.height); + + videoInverted = new unsigned char[camWidth*camHeight*3]; + videoTexture.allocate(camWidth,camHeight, GL_RGB); + } //-------------------------------------------------------------- void testApp::update(){ texture.idleMovie(); + + if (mode==GRAB) { + vidGrabber.grabFrame(); + + if (vidGrabber.isFrameNew()){ + int totalPixels = camWidth*camHeight*3; + unsigned char * pixels = vidGrabber.getPixels(); + for (int i = 0; i < totalPixels; i+=3){ + unsigned int bright= (pixels[i]>>2)+ (pixels[i+1]>>1)+(pixels[i+1]>>2); //(0.2126*R) + (0.7152*G) + (0.0722*B) + videoInverted[i] = (unsigned char)((226*bright)>>8); + videoInverted[i+1] = (unsigned char)((200*bright)>>8); + videoInverted[i+2] = (unsigned char)((20*bright)>>8); + } + videoTexture.loadData(videoInverted, camWidth,camHeight, GL_RGB); + } + } } //-------------------------------------------------------------- @@ -75,6 +105,14 @@ void testApp::draw(){ ofPopMatrix(); unbindTexture(texture); break; + case GRAB: + bindTex(videoTexture); + ofPushMatrix(); + ofRotate(90,0,1,0); + model.draw(); + ofPopMatrix(); + unbindTex(videoTexture); + break; case NOTHING: bindTexture(texture); glPushMatrix(); @@ -103,7 +141,7 @@ void testApp::keyPressed(int key){ mode=DISPLAY; break; case '0': - mode=NOTHING; + mode=GRAB; break; case '1': activeView=-1; |
