structure

This commit is contained in:
micuat 2020-10-19 17:15:16 +02:00
parent 4aa1d62480
commit bdbd2c76af
2 changed files with 104 additions and 97 deletions

View file

@ -4,13 +4,8 @@
int camWidth = 640; int camWidth = 640;
int camHeight = 480; int camHeight = 480;
//-------------------------------------------------------------- void ofApp::setupKinect()
void ofApp::setup()
{ {
ofDisableArbTex();
ofSetVerticalSync(false);
//ofSetLogLevel(OF_LOG_VERBOSE);
ofLogNotice(__FUNCTION__) << "Found " << ofxAzureKinect::Device::getInstalledCount() << " installed devices."; ofLogNotice(__FUNCTION__) << "Found " << ofxAzureKinect::Device::getInstalledCount() << " installed devices.";
// Open Kinect. // Open Kinect.
@ -25,15 +20,6 @@ void ofApp::setup()
} }
// Load shader. // 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"); shader.load("shaders/render.vert", "shaders/render.frag", "shaders/render.geom");
// Setup vbo. // Setup vbo.
@ -42,13 +28,10 @@ void ofApp::setup()
pointSize = 2.0f; pointSize = 2.0f;
useColorSpace = false; useColorSpace = false;
}
boundShader.allocate(ofGetWidth(), ofGetHeight()); void ofApp::setupThermal()
boundShader.load("shaders/bound.frag"); {
fbos.insert({"ofcam", ofFbo()});
fbos.at("ofcam").allocate(ofGetWidth(), ofGetHeight(), GL_RGB32F_ARB);
// this must be called before init (otherwise fprintf will tell you so) // 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 // 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 // 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 a texture because the ofxV4L2 class has no draw method (yet)
// we use GL_LUMINANCE because the ofxV4L2 class supports only grayscale (for now) // we use GL_LUMINANCE because the ofxV4L2 class supports only grayscale (for now)
v4l2Tex.allocate(camWidth, camHeight, GL_LUMINANCE); 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"); gradient.load("gradient.png");
} }
//--------------------------------------------------------------
void ofApp::exit() void ofApp::exit()
{ {
kinectDevice.close(); kinectDevice.close();
} }
//-------------------------------------------------------------- void ofApp::updateThermal()
void ofApp::update()
{ {
v4l2Cam.grabFrame(); v4l2Cam.grabFrame();
if (v4l2Cam.isNewFrame()) if (v4l2Cam.isNewFrame())
{ {
// v4l2Tex.loadData(v4l2Cam.getPixels(), camWidth, camHeight, GL_RED);
ofPixels p; ofPixels p;
p.allocate(camWidth, camHeight, OF_PIXELS_RGB); p.allocate(camWidth, camHeight, OF_PIXELS_RGB);
for (int i = 0; i < camHeight * camWidth; i++) for (int i = 0; i < camHeight * camWidth; i++)
p.setColor(i, v4l2Cam.getPixels()[i]); p.setColor(i, v4l2Cam.getPixels()[i]);
v4l2Tex.allocate(p); v4l2Tex.allocate(p);
// v4l2Tex.setRGToRGBASwizzles(true);
// ofLogError() << v4l2Cam.getPixels();
} }
} }
//-------------------------------------------------------------- void ofApp::update()
void ofApp::draw()
{ {
ofBackground(0); updateThermal();
}
if (kinectDevice.isStreaming()) void ofApp::drawKinect()
{ {
fbos.at("ofcam").begin();
ofClear(0); ofClear(0);
cam.begin(); cam.begin();
ofEnableDepthTest(); ofEnableDepthTest();
@ -146,8 +139,10 @@ void ofApp::draw()
shader.end(); shader.end();
ofPopMatrix(); ofPopMatrix();
cam.end(); cam.end();
fbos.at("ofcam").end(); }
void ofApp::drawMain()
{
ofDisableDepthTest(); ofDisableDepthTest();
auto tex = kinectDevice.getDepthTex(); auto tex = kinectDevice.getDepthTex();
boundShader.setUniformTexture("u_depth", tex); boundShader.setUniformTexture("u_depth", tex);
@ -161,14 +156,30 @@ void ofApp::draw()
{ {
boundShader.render(); boundShader.render();
} }
boundShader.draw(0, 0);
} }
// v4l2Tex.draw(0, 0);
void ofApp::drawDebug()
{
ofDrawBitmapStringHighlight(ofToString(ofGetFrameRate(), 2) + " FPS", 10, 20); 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) void ofApp::keyPressed(int key)
{ {
if (key == 'w') if (key == 'w')
@ -185,52 +196,42 @@ void ofApp::keyPressed(int key)
} }
} }
//--------------------------------------------------------------
void ofApp::keyReleased(int key) void ofApp::keyReleased(int key)
{ {
} }
//--------------------------------------------------------------
void ofApp::mouseMoved(int x, int y) void ofApp::mouseMoved(int x, int y)
{ {
} }
//--------------------------------------------------------------
void ofApp::mouseDragged(int x, int y, int button) void ofApp::mouseDragged(int x, int y, int button)
{ {
} }
//--------------------------------------------------------------
void ofApp::mousePressed(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::mouseReleased(int x, int y, int button)
{ {
} }
//--------------------------------------------------------------
void ofApp::mouseEntered(int x, int y) void ofApp::mouseEntered(int x, int y)
{ {
} }
//--------------------------------------------------------------
void ofApp::mouseExited(int x, int y) void ofApp::mouseExited(int x, int y)
{ {
} }
//--------------------------------------------------------------
void ofApp::windowResized(int w, int h) void ofApp::windowResized(int w, int h)
{ {
} }
//--------------------------------------------------------------
void ofApp::gotMessage(ofMessage msg) void ofApp::gotMessage(ofMessage msg)
{ {
} }
//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo) void ofApp::dragEvent(ofDragInfo dragInfo)
{ {
} }

View file

@ -12,10 +12,16 @@ class ofApp
: public ofBaseApp : public ofBaseApp
{ {
public: public:
void setupKinect();
void setupThermal();
void setup(); void setup();
void exit(); void exit();
void updateThermal();
void update(); void update();
void drawKinect();
void drawMain();
void drawDebug();
void draw(); void draw();
void keyPressed(int key); void keyPressed(int key);