structure
This commit is contained in:
parent
4aa1d62480
commit
bdbd2c76af
2 changed files with 104 additions and 97 deletions
|
@ -4,13 +4,8 @@
|
|||
int camWidth = 640;
|
||||
int camHeight = 480;
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void ofApp::setup()
|
||||
void ofApp::setupKinect()
|
||||
{
|
||||
ofDisableArbTex();
|
||||
ofSetVerticalSync(false);
|
||||
//ofSetLogLevel(OF_LOG_VERBOSE);
|
||||
|
||||
ofLogNotice(__FUNCTION__) << "Found " << ofxAzureKinect::Device::getInstalledCount() << " installed devices.";
|
||||
|
||||
// Open Kinect.
|
||||
|
@ -25,15 +20,6 @@ void ofApp::setup()
|
|||
}
|
||||
|
||||
// Load shader.
|
||||
// auto shaderSettings = ofShaderSettings();
|
||||
// shaderSettings.shaderFiles[GL_VERTEX_SHADER] = "shaders/render.vert";
|
||||
// shaderSettings.shaderFiles[GL_GEOMETRY_SHADER] = "shaders/render.geom";
|
||||
// shaderSettings.shaderFiles[GL_FRAGMENT_SHADER] = "shaders/render.frag";
|
||||
// shaderSettings.bindDefaults = true;
|
||||
// if (shader.setup(shaderSettings))
|
||||
// {
|
||||
// ofLogNotice(__FUNCTION__) << "Success loading shader!";
|
||||
// }
|
||||
shader.load("shaders/render.vert", "shaders/render.frag", "shaders/render.geom");
|
||||
|
||||
// Setup vbo.
|
||||
|
@ -42,13 +28,10 @@ void ofApp::setup()
|
|||
|
||||
pointSize = 2.0f;
|
||||
useColorSpace = false;
|
||||
}
|
||||
|
||||
boundShader.allocate(ofGetWidth(), ofGetHeight());
|
||||
boundShader.load("shaders/bound.frag");
|
||||
|
||||
fbos.insert({"ofcam", ofFbo()});
|
||||
fbos.at("ofcam").allocate(ofGetWidth(), ofGetHeight(), GL_RGB32F_ARB);
|
||||
|
||||
void ofApp::setupThermal()
|
||||
{
|
||||
// this must be called before init (otherwise fprintf will tell you so)
|
||||
// note that high framerates will only function properly if the usb has enough bandwidth
|
||||
// for example, a ps3 eye cam at 60 fps will only function when it has full USB 2.0 bandwidth available
|
||||
|
@ -68,41 +51,51 @@ void ofApp::setup()
|
|||
// we use a texture because the ofxV4L2 class has no draw method (yet)
|
||||
// we use GL_LUMINANCE because the ofxV4L2 class supports only grayscale (for now)
|
||||
v4l2Tex.allocate(camWidth, camHeight, GL_LUMINANCE);
|
||||
}
|
||||
|
||||
void ofApp::setup()
|
||||
{
|
||||
ofDisableArbTex();
|
||||
ofSetVerticalSync(false);
|
||||
//ofSetLogLevel(OF_LOG_VERBOSE);
|
||||
|
||||
setupKinect();
|
||||
setupThermal();
|
||||
|
||||
boundShader.allocate(ofGetWidth(), ofGetHeight());
|
||||
boundShader.load("shaders/bound.frag");
|
||||
|
||||
fbos.insert({"ofcam", ofFbo()});
|
||||
fbos.at("ofcam").allocate(ofGetWidth(), ofGetHeight(), GL_RGB32F_ARB);
|
||||
|
||||
gradient.load("gradient.png");
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void ofApp::exit()
|
||||
{
|
||||
kinectDevice.close();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void ofApp::update()
|
||||
void ofApp::updateThermal()
|
||||
{
|
||||
v4l2Cam.grabFrame();
|
||||
if (v4l2Cam.isNewFrame())
|
||||
{
|
||||
// v4l2Tex.loadData(v4l2Cam.getPixels(), camWidth, camHeight, GL_RED);
|
||||
ofPixels p;
|
||||
p.allocate(camWidth, camHeight, OF_PIXELS_RGB);
|
||||
for (int i = 0; i < camHeight * camWidth; i++)
|
||||
p.setColor(i, v4l2Cam.getPixels()[i]);
|
||||
v4l2Tex.allocate(p);
|
||||
// v4l2Tex.setRGToRGBASwizzles(true);
|
||||
// ofLogError() << v4l2Cam.getPixels();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void ofApp::draw()
|
||||
void ofApp::update()
|
||||
{
|
||||
ofBackground(0);
|
||||
updateThermal();
|
||||
}
|
||||
|
||||
if (kinectDevice.isStreaming())
|
||||
{
|
||||
fbos.at("ofcam").begin();
|
||||
void ofApp::drawKinect()
|
||||
{
|
||||
ofClear(0);
|
||||
cam.begin();
|
||||
ofEnableDepthTest();
|
||||
|
@ -146,8 +139,10 @@ void ofApp::draw()
|
|||
shader.end();
|
||||
ofPopMatrix();
|
||||
cam.end();
|
||||
fbos.at("ofcam").end();
|
||||
}
|
||||
|
||||
void ofApp::drawMain()
|
||||
{
|
||||
ofDisableDepthTest();
|
||||
auto tex = kinectDevice.getDepthTex();
|
||||
boundShader.setUniformTexture("u_depth", tex);
|
||||
|
@ -161,14 +156,30 @@ void ofApp::draw()
|
|||
{
|
||||
boundShader.render();
|
||||
}
|
||||
boundShader.draw(0, 0);
|
||||
}
|
||||
// v4l2Tex.draw(0, 0);
|
||||
}
|
||||
|
||||
void ofApp::drawDebug()
|
||||
{
|
||||
ofDrawBitmapStringHighlight(ofToString(ofGetFrameRate(), 2) + " FPS", 10, 20);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void ofApp::draw()
|
||||
{
|
||||
ofBackground(0);
|
||||
|
||||
if (kinectDevice.isStreaming())
|
||||
{
|
||||
fbos.at("ofcam").begin();
|
||||
drawKinect();
|
||||
fbos.at("ofcam").end();
|
||||
|
||||
drawMain();
|
||||
boundShader.draw(0, 0);
|
||||
}
|
||||
|
||||
drawDebug();
|
||||
}
|
||||
|
||||
void ofApp::keyPressed(int key)
|
||||
{
|
||||
if (key == 'w')
|
||||
|
@ -185,52 +196,42 @@ void ofApp::keyPressed(int key)
|
|||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void ofApp::keyReleased(int key)
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void ofApp::mouseMoved(int x, int y)
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void ofApp::mouseDragged(int x, int y, int button)
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void ofApp::mousePressed(int x, int y, int button)
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void ofApp::mouseReleased(int x, int y, int button)
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void ofApp::mouseEntered(int x, int y)
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void ofApp::mouseExited(int x, int y)
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void ofApp::windowResized(int w, int h)
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void ofApp::gotMessage(ofMessage msg)
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void ofApp::dragEvent(ofDragInfo dragInfo)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -12,10 +12,16 @@ class ofApp
|
|||
: public ofBaseApp
|
||||
{
|
||||
public:
|
||||
void setupKinect();
|
||||
void setupThermal();
|
||||
void setup();
|
||||
void exit();
|
||||
|
||||
void updateThermal();
|
||||
void update();
|
||||
void drawKinect();
|
||||
void drawMain();
|
||||
void drawDebug();
|
||||
void draw();
|
||||
|
||||
void keyPressed(int key);
|
||||
|
|
Loading…
Reference in a new issue