From d859084ee38614e31a15cda0c2af1f23494483ba Mon Sep 17 00:00:00 2001 From: cailean Date: Tue, 1 Oct 2024 18:43:23 +0100 Subject: [PATCH] tex coords wont work! --- src/Map.cpp | 1 - src/Onnx.cpp | 5 +---- src/Onnx.h | 2 +- src/main.cpp | 1 + src/ofApp.cpp | 28 ++++++++++++++++++++++++---- src/ofApp.h | 2 ++ 6 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/Map.cpp b/src/Map.cpp index ffae41e..daa8118 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -6,7 +6,6 @@ Map::Map(){ } void Map::Setup(){ - ofDisableArbTex(); scale = 10000; isDebug = true; diff --git a/src/Onnx.cpp b/src/Onnx.cpp index 62e468d..64d2e5c 100644 --- a/src/Onnx.cpp +++ b/src/Onnx.cpp @@ -228,7 +228,7 @@ void Onnx::Normalize(float* data, size_t size, float min_value, float max_value) } // Coverts the output tensor data to a texture of a given ofFbo. -void Onnx::DataToFbo(const float* data, size_t width, size_t height, ofFbo& fbo, ofShader& shader){ +void Onnx::DataToFbo(const float* data, size_t width, size_t height, ofFbo& fbo){ // Convert data into opencv mat cv::Mat inputMat(height, width, CV_32FC1, const_cast(data)); @@ -254,11 +254,8 @@ void Onnx::DataToFbo(const float* data, size_t width, size_t height, ofFbo& fbo, // Update FBO with new pixels fbo.begin(); - shader.begin(); ofTexture& texture = fbo.getTexture(); texture.loadData(pixels); - shader.setUniformTexture("tex", texture, 0); - shader.end(); fbo.end(); diff --git a/src/Onnx.h b/src/Onnx.h index 65299bc..0ce95d8 100644 --- a/src/Onnx.h +++ b/src/Onnx.h @@ -31,7 +31,7 @@ float ReduceMin(const float* data, size_t size); float ReduceMax(const float* data, size_t size); void Normalize(float* data, size_t size, float min_value, float max_value); - void DataToFbo(const float* data, size_t width, size_t height, ofFbo& fbo, ofShader& shader); + void DataToFbo(const float* data, size_t width, size_t height, ofFbo& fbo); void Softmax(float* data, size_t size); bool timeStamp = false; bool log = false; diff --git a/src/main.cpp b/src/main.cpp index c35763d..7592dfd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,6 +7,7 @@ int main( ){ //Use ofGLFWWindowSettings for more options like multi-monitor fullscreen ofGLWindowSettings settings; settings.setSize(1600, 800); + settings.setGLVersion(3, 2); settings.windowMode = OF_WINDOW; //can also be OF_FULLSCREEN auto window = ofCreateWindow(settings); diff --git a/src/ofApp.cpp b/src/ofApp.cpp index 0d30b95..f43cf6b 100644 --- a/src/ofApp.cpp +++ b/src/ofApp.cpp @@ -2,6 +2,7 @@ //-------------------------------------------------------------- void ofApp::setup(){ + ofDisableArbTex(); ofSetFrameRate(24); ofSetVerticalSync(true); @@ -23,6 +24,8 @@ void ofApp::setup(){ emotion.Setup(modelPath3, false, true); depthToColourShader.load("data/shader/rampShader.vert", "data/shader/rampShader.frag"); + rampedFbo.allocate(1600, 800, GL_RGB); + drawMesh =ofMesh::plane(1600, 800 ); } @@ -60,7 +63,7 @@ void ofApp::update(){ depth.Normalize(output_ptr, num_elements, min_value, max_value); - depth.DataToFbo(output_ptr, 518, 518, fbo, depthToColourShader); + depth.DataToFbo(output_ptr, 518, 518, fbo); auto output_tensors_face = yolo.Run(map.fboImage); @@ -110,10 +113,27 @@ void ofApp::update(){ //-------------------------------------------------------------- void ofApp::draw(){ - map.Draw(); - - fbo.draw(0, 0); + //fbo.draw(0, 0); + + auto& texCoords = drawMesh.getTexCoords(); + auto& tex = rampedFbo.getTexture(); + for( auto& tc : texCoords ){ + tc = rampedFbo.getTexture().getCoordFromPercent(tc.x, (1.0-tc.y)); + } + + rampedFbo.begin(); + depthToColourShader.begin(); + depthToColourShader.setUniformTexture("alphaTex", fbo.getTexture(), 0); + ofPushMatrix(); + // translate to center of window because ofMesh::plane origin is in the center // + ofTranslate(ofGetWidth()/2, ofGetHeight()/2 ); + drawMesh.draw(); + ofPopMatrix(); + depthToColourShader.end(); + rampedFbo.end(); + + rampedFbo.draw(0, 0); if(!firstRun){ faceDetector.DrawBox(detected_faces); diff --git a/src/ofApp.h b/src/ofApp.h index 6d23674..3ebb12f 100644 --- a/src/ofApp.h +++ b/src/ofApp.h @@ -51,4 +51,6 @@ class ofApp : public ofBaseApp{ Map map; ofShader depthToColourShader; + ofFbo rampedFbo; + ofMesh drawMesh; };