From 3d5588a7ead64f3b11ef132f21469b9471819850 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Wed, 21 Mar 2012 20:48:21 +0000 Subject: misc --- bin/data/settings.xml | 36 ++++++++++++++++++++++++------------ src/mapUtils.cpp | 29 ++++++++++++++++++++++++++--- src/mapUtils.h | 2 ++ src/testApp.cpp | 40 +++++++++++++++++++++++++++++++++++++++- src/testApp.h | 13 +++++++++++-- 5 files changed, 102 insertions(+), 18 deletions(-) diff --git a/bin/data/settings.xml b/bin/data/settings.xml index b475f2d..893a793 100644 --- a/bin/data/settings.xml +++ b/bin/data/settings.xml @@ -1,27 +1,39 @@ - + - + - + - + - - + + - - + + - - + + - - + + + + + + + + + + + + + + diff --git a/src/mapUtils.cpp b/src/mapUtils.cpp index 3787bf4..3dd3d7c 100644 --- a/src/mapUtils.cpp +++ b/src/mapUtils.cpp @@ -33,6 +33,29 @@ void unbindTexture(ofBaseHasTexture &t) { glPopMatrix(); glMatrixMode(GL_MODELVIEW); } +void bindTex(ofTexture &tex) { + tex.bind(); + + glMatrixMode(GL_TEXTURE); + glPushMatrix(); + glLoadIdentity(); + + ofTextureData texData = tex.getTextureData(); + if(texData.textureTarget == GL_TEXTURE_RECTANGLE_ARB) { + glScalef(tex.getWidth(), tex.getHeight(), 1.0f); + } else { + glScalef(tex.getWidth() / texData.tex_w, tex.getHeight() / texData.tex_h, 1.0f); + } + + glMatrixMode(GL_MODELVIEW); +} +void unbindTex(ofTexture &tex) { + tex.unbind(); + + glMatrixMode(GL_TEXTURE); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); +} ofPoint distort(ofPoint pt,float d){ //normalised coords -1..1, d float r=pow(pow(pow(pt.x,2.0f)+pow(pt.y,2.0f),0.5f),1.0f+d); @@ -89,17 +112,17 @@ void drawBoard(float x,float y,float z) { glVertex3f(cx+8, 0, cz+8); glVertex3f(cx+4, 0, cz+4); glVertex3f(cx+4, 0, cz-4); - + glVertex3f(cx+4, 0, cz+4); glVertex3f(cx+8, 0, cz+8); glVertex3f(cx-8, 0, cz+8); glVertex3f(cx-4, 0, cz+4); - + glVertex3f(cx-4, 0, cz-4); glVertex3f(cx-4, 0, cz+4); glVertex3f(cx-8, 0, cz+8); glVertex3f(cx-8, 0, cz-8); - + glVertex3f(cx+8, 0, cz-8); glVertex3f(cx+4, 0, cz-4); glVertex3f(cx-4, 0, cz-4); diff --git a/src/mapUtils.h b/src/mapUtils.h index 97af934..4c56b2d 100644 --- a/src/mapUtils.h +++ b/src/mapUtils.h @@ -11,6 +11,8 @@ void bindTexture(ofBaseHasTexture &t); void unbindTexture(ofBaseHasTexture &t); +void bindTex(ofTexture &tex); +void unbindTex(ofTexture &tex); ofPoint distort(ofPoint pt,float d); void drawBox(float size); void drawBoard(float x,float y,float z); 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; diff --git a/src/testApp.h b/src/testApp.h index 24bcbe9..32dae89 100644 --- a/src/testApp.h +++ b/src/testApp.h @@ -22,7 +22,9 @@ have to track how many frames each key has been pressed for #define CALIBRATE 1 #define DISPLAY 2 -#define NOTHING 3 +#define GRAB 3 +#define NOTHING 4 + #include "ofMain.h" #include "ofxXmlSettings.h" @@ -72,5 +74,12 @@ class testApp : public ofBaseApp{ ofxXmlSettings XML; bool light; - + + ofVideoGrabber vidGrabber; + + unsigned char * videoInverted; + ofTexture videoTexture; + int camWidth; + int camHeight; + }; -- cgit v1.2.3