From 3d5588a7ead64f3b11ef132f21469b9471819850 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Wed, 21 Mar 2012 20:48:21 +0000 Subject: misc --- src/testApp.cpp | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'src/testApp.cpp') 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); + } + } } //-------------------------------------------------------------- @@ -74,6 +104,14 @@ void testApp::draw(){ model.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); @@ -103,7 +141,7 @@ void testApp::keyPressed(int key){ mode=DISPLAY; break; case '0': - mode=NOTHING; + mode=GRAB; break; case '1': activeView=-1; -- cgit v1.2.3