@@ -65,16 +65,14 @@ OutputWindow::OutputWindow() : PatchObject("output window"){
6565 window_actual_width = STANDARD_PROJECTOR_WINDOW_WIDTH;
6666 window_actual_height = STANDARD_PROJECTOR_WINDOW_HEIGHT;
6767
68- warpedTexture = new ofFbo ();
69-
7068 useMapping = false ;
7169 edgesLuminance = 0 .5f ;
7270 edgesGamma = 1 .0f ;
7371 edgesExponent = 1 .0f ;
7472 edgeL = edgeR = edgeT = edgeB = 0 .5f ;
7573
7674 needReset = false ;
77- isWarpingLoaded = false ;
75+ hideMouse = false ;
7876
7977 loadWarpingFlag = false ;
8078 saveWarpingFlag = false ;
@@ -101,6 +99,7 @@ void OutputWindow::newObject(){
10199 this ->setCustomVar (0 .0f ," OUTPUT_POSX" );
102100 this ->setCustomVar (0 .0f ," OUTPUT_POSY" );
103101 this ->setCustomVar (static_cast <float >(useMapping)," USE_MAPPING" );
102+ this ->setCustomVar (static_cast <float >(hideMouse)," HIDE_MOUSE" );
104103 this ->setCustomVar (edgesLuminance," EDGES_LUMINANCE" );
105104 this ->setCustomVar (edgesGamma," EDGES_GAMMA" );
106105 this ->setCustomVar (edgesExponent," EDGES_EXPONENT" );
@@ -151,18 +150,10 @@ void OutputWindow::setupObjectContent(shared_ptr<ofAppGLFWWindow> &mainWindow){
151150 ofAddListener (window->events ().mouseScrolled ,this ,&OutputWindow::mouseScrolled);
152151 ofAddListener (window->events ().windowResized ,this ,&OutputWindow::windowResized);
153152
154- static_cast <ofTexture *>(_inletParams[0 ])->allocate (this ->output_width ,this ->output_height ,GL_RGBA32F_ARB);
155- warpedTexture->allocate (this ->output_width ,this ->output_height ,GL_RGBA32F_ARB,4 );
156-
157153 if (static_cast <ofTexture *>(_inletParams[0 ])->isAllocated ()){
158154 ofLog (OF_LOG_NOTICE," %s: NEW PROJECTOR WINDOW CREATED WITH RESOLUTION %ix%i" ,this ->name .c_str (),this ->output_width ,this ->output_height );
159155 }
160156
161- // setup drawing dimensions
162- asRatio = reduceToAspectRatio (this ->output_width ,this ->output_height );
163- window_asRatio = reduceToAspectRatio (window->getWidth (),window->getHeight ());
164- scaleTextureToWindow (window->getWidth (),window->getHeight ());
165-
166157 // init outlet mouse data
167158 static_cast <vector<float > *>(_outletParams[0 ])->assign (3 ,0 .0f );
168159
@@ -175,21 +166,41 @@ void OutputWindow::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchOb
175166
176167 if (needReset){
177168 needReset = false ;
178- resetOutputResolution ();
169+ int fromObjID = -1 ;
170+ int fromOutletID = -1 ;
171+ bool isSpecialLink = false ;
179172 if (this ->inletsConnected [0 ]){
180173 for (map<int ,shared_ptr<PatchObject>>::iterator it = patchObjects.begin (); it != patchObjects.end (); it++ ){
181174 if (patchObjects[it->first ] != nullptr && it->first != this ->getId () && !patchObjects[it->first ]->getWillErase ()){
182175 for (int o=0 ;o<static_cast <int >(it->second ->outPut .size ());o++){
183176 if (!it->second ->outPut [o]->isDisabled && it->second ->outPut [o]->toObjectID == this ->getId ()){
177+ fromObjID = it->first ;
178+ fromOutletID = it->second ->outPut [o]->fromOutletID ;
184179 if (it->second ->getName () == " lua script" || it->second ->getName () == " glsl shader" ){
185180 it->second ->resetResolution (this ->getId (),this ->output_width ,this ->output_height );
181+ isSpecialLink = true ;
186182 break ;
187183 }
188184 }
189185 }
190186 }
191187 }
192188 }
189+ // reset
190+ resetOutputResolution ();
191+ if (this ->inletsConnected [0 ] && fromObjID != -1 && fromOutletID != -1 ){
192+ this ->disconnectFrom (patchObjects,0 );
193+ std::this_thread::sleep_for (std::chrono::milliseconds (50 ));
194+ this ->connectTo (patchObjects,fromObjID,fromOutletID,0 ,VP_LINK_TEXTURE);
195+
196+ if (isSpecialLink){
197+ if (!isFullscreen){
198+ scaleTextureToWindow (this ->output_width ,this ->output_height , window_actual_width, window_actual_height);
199+ }else {
200+ scaleTextureToWindow (this ->output_width ,this ->output_height , window->getScreenSize ().x ,window->getScreenSize ().y );
201+ }
202+ }
203+ }
193204 }
194205
195206 // Manage the different scripts reference available (ofxLua)
@@ -217,13 +228,37 @@ void OutputWindow::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchOb
217228 temp_width = static_cast <int >(floor (this ->getCustomVar (" OUTPUT_WIDTH" )));
218229 temp_height = static_cast <int >(floor (this ->getCustomVar (" OUTPUT_HEIGHT" )));
219230 useMapping = static_cast <int >(floor (this ->getCustomVar (" USE_MAPPING" )));
231+ hideMouse = static_cast <int >(floor (this ->getCustomVar (" HIDE_MOUSE" )));
220232 edgesLuminance = this ->getCustomVar (" EDGES_LUMINANCE" );
221233 edgesGamma = this ->getCustomVar (" EDGES_GAMMA" );
222234 edgesExponent = this ->getCustomVar (" EDGES_EXPONENT" );
223235 edgeL = this ->getCustomVar (" EDGE_LEFT" );
224236 edgeR = this ->getCustomVar (" EDGE_RIGHT" );
225237 edgeT = this ->getCustomVar (" EDGE_TOP" );
226238 edgeB = this ->getCustomVar (" EDGE_BOTTOM" );
239+
240+ // setup drawing dimensions
241+ if (inletsConnected[0 ]){
242+ scaleTextureToWindow (static_cast <ofTexture *>(_inletParams[0 ])->getWidth (), static_cast <ofTexture *>(_inletParams[0 ])->getHeight (), window->getWidth (),window->getHeight ());
243+ }else {
244+ scaleTextureToWindow (STANDARD_TEXTURE_WIDTH, STANDARD_TEXTURE_HEIGHT, window->getWidth (),window->getHeight ());
245+ }
246+
247+
248+ // setup warping
249+ warpController = new ofxWarpController ();
250+ if (filepath != " none" ){
251+ warpController->loadSettings (filepath);
252+ }else {
253+ warpController->buildWarp <ofxWarpPerspectiveBilinear>();
254+ }
255+
256+ warpController->getWarp (0 )->setSize (window->getScreenSize ().x ,window->getScreenSize ().y );
257+ warpController->getWarp (0 )->setEdges (glm::vec4 (edgeL, edgeT, edgeR, edgeB));
258+ warpController->getWarp (0 )->setLuminance (edgesLuminance);
259+ warpController->getWarp (0 )->setGamma (edgesGamma);
260+ warpController->getWarp (0 )->setExponent (edgesExponent);
261+
227262 if (static_cast <bool >(floor (this ->getCustomVar (" FULLSCREEN" ))) != isFullscreen){
228263 window->setWindowPosition (this ->getCustomVar (" OUTPUT_POSX" ),this ->getCustomVar (" OUTPUT_POSY" ));
229264 toggleWindowFullscreen ();
@@ -342,33 +377,21 @@ void OutputWindow::drawObjectNodeConfig(){
342377 if (ImGui::Button (" APPLY" ,ImVec2 (224 *scaleFactor,26 *scaleFactor))){
343378 needReset = true ;
344379 }
380+ ImGui::Spacing ();
381+ ImGui::Spacing ();
382+ if (ImGui::Checkbox (" HIDE MOUSE" ,&hideMouse)){
383+ this ->setCustomVar (hideMouse," HIDE_MOUSE" );
384+ }
345385
346386 ImGui::Separator ();
347387
348388 ImGui::Spacing ();
349389 if (ImGui::Checkbox (" WARPING" ,&useMapping)){
350390 this ->setCustomVar (useMapping," USE_MAPPING" );
351- if (useMapping){
352- if (!isWarpingLoaded){
353- isWarpingLoaded = true ;
354- // setup warping (warping first load)
355- warpController = new ofxWarpController ();
356- if (filepath != " none" ){
357- warpController->loadSettings (filepath);
358- }else {
359- shared_ptr<ofxWarpPerspectiveBilinear> warp = warpController->buildWarp <ofxWarpPerspectiveBilinear>();
360- warp->setSize (window->getScreenSize ().x ,window->getScreenSize ().y );
361- warp->setEdges (glm::vec4 (this ->getCustomVar (" EDGE_LEFT" ), this ->getCustomVar (" EDGE_TOP" ), this ->getCustomVar (" EDGE_RIGHT" ), this ->getCustomVar (" EDGE_BOTTOM" )));
362- warp->setLuminance (this ->getCustomVar (" EDGES_LUMINANCE" ));
363- warp->setGamma (this ->getCustomVar (" EDGES_GAMMA" ));
364- warp->setExponent (this ->getCustomVar (" EDGES_EXPONENT" ));
365- }
366- }
367- }
368391 }
369392 ImGui::SameLine (); ImGuiEx::HelpMarker (" Warping can be visualized/edited only in fullscreen mode!" );
370393
371- if (useMapping && isWarpingLoaded ){
394+ if (useMapping){
372395 ImGui::Spacing ();
373396 if (ImGui::SliderFloat (" Luminance" ,&edgesLuminance,0 .0f ,1 .0f )){
374397 this ->setCustomVar (edgesLuminance," EDGES_LUMINANCE" );
@@ -466,44 +489,22 @@ void OutputWindow::removeObjectContent(bool removeFileFromData){
466489}
467490
468491// --------------------------------------------------------------
469- glm::vec2 OutputWindow::reduceToAspectRatio (int _w, int _h){
470- glm::vec2 _res;
471- int temp = _w*_h;
472- if (temp>0 ){
473- for (int tt = temp; tt>1 ; tt--){
474- if ((_w%tt==0 ) && (_h%tt==0 )){
475- _w/=tt;
476- _h/=tt;
477- }
478- }
479- }else if (temp<0 ){
480- for (int tt = temp; tt<-1 ; tt++){
481- if ((_w%tt==0 ) && (_h%tt==0 )){
482- _w/=tt;
483- _h/=tt;
484- }
485- }
486- }
487- _res = glm::vec2 (_w,_h);
488- return _res;
489- }
490-
491- // --------------------------------------------------------------
492- void OutputWindow::scaleTextureToWindow (int theScreenW, int theScreenH){
493- // wider texture than screen
494- if (asRatio.x /asRatio.y >= window_asRatio.x /window_asRatio.y ){
495- thdrawW = theScreenW;
496- thdrawH = (this ->output_height *theScreenW) / this ->output_width ;
492+ void OutputWindow::scaleTextureToWindow (float texW, float texH, float winW, float winH){
493+ // wider texture than window
494+ if (texW/texH >= winW/winH){
495+ thdrawW = winW;
496+ thdrawH = (texH*winW) / texW;
497497 thposX = 0 ;
498- thposY = (theScreenH-thdrawH)/2 .0f ;
499- // wider screen than texture
498+ thposY = (winH-thdrawH)/2 .0f ;
499+ // ofLog(OF_LOG_NOTICE," |wider texture than window| Window: %fx%f, Texture[%fx%f] drawing %fx%f at %f,%f",winW,winH,texW,texH,thdrawW,thdrawH,thposX,thposY);
500+ // wider window than texture
500501 }else {
501- thdrawW = (this -> output_width *theScreenH ) / this -> output_height ;
502- thdrawH = theScreenH ;
503- thposX = (theScreenW -thdrawW)/2 .0f ;
502+ thdrawW = (texW*winH ) / texH ;
503+ thdrawH = winH ;
504+ thposX = (winW -thdrawW)/2 .0f ;
504505 thposY = 0 ;
506+ // ofLog(OF_LOG_NOTICE," |wider window than texture| Window: %fx%f, Texture[%fx%f] drawing %fx%f at %f,%f",winW,winH,texW,texH,thdrawW,thdrawH,thposX,thposY);
505507 }
506- // ofLog(OF_LOG_NOTICE,"Window: %ix%i, Texture; %fx%f at %f,%f",theScreenW,theScreenH,thdrawW,thdrawH,thposX,thposY);
507508}
508509
509510// --------------------------------------------------------------
@@ -515,24 +516,9 @@ void OutputWindow::toggleWindowFullscreen(){
515516
516517 if (!isFullscreen){
517518 window->setWindowShape (window_actual_width, window_actual_height);
518- scaleTextureToWindow (window_actual_width, window_actual_height);
519+ scaleTextureToWindow (static_cast <ofTexture *>(_inletParams[ 0 ])-> getWidth (), static_cast <ofTexture *>(_inletParams[ 0 ])-> getHeight (), window_actual_width, window_actual_height);
519520 }else {
520- scaleTextureToWindow (window->getScreenSize ().x ,window->getScreenSize ().y );
521- if (!isWarpingLoaded){
522- isWarpingLoaded = true ;
523- // setup warping (warping first load)
524- warpController = new ofxWarpController ();
525- if (filepath != " none" ){
526- warpController->loadSettings (filepath);
527- }else {
528- shared_ptr<ofxWarpPerspectiveBilinear> warp = warpController->buildWarp <ofxWarpPerspectiveBilinear>();
529- warp->setSize (window->getScreenSize ().x ,window->getScreenSize ().y );
530- warp->setEdges (glm::vec4 (this ->getCustomVar (" EDGE_LEFT" ), this ->getCustomVar (" EDGE_TOP" ), this ->getCustomVar (" EDGE_RIGHT" ), this ->getCustomVar (" EDGE_BOTTOM" )));
531- warp->setLuminance (this ->getCustomVar (" EDGES_LUMINANCE" ));
532- warp->setGamma (this ->getCustomVar (" EDGES_GAMMA" ));
533- warp->setExponent (this ->getCustomVar (" EDGES_EXPONENT" ));
534- }
535- }
521+ scaleTextureToWindow (static_cast <ofTexture *>(_inletParams[0 ])->getWidth (), static_cast <ofTexture *>(_inletParams[0 ])->getHeight (), window->getScreenSize ().x ,window->getScreenSize ().y );
536522 }
537523
538524 this ->setCustomVar (window->getWindowPosition ().x ," OUTPUT_POSX" );
@@ -543,24 +529,21 @@ void OutputWindow::toggleWindowFullscreen(){
543529void OutputWindow::drawInWindow (ofEventArgs &e){
544530 ofBackground (0 );
545531
532+ if (hideMouse){
533+ window->hideCursor ();
534+ }else {
535+ window->showCursor ();
536+ }
537+
546538 ofPushStyle ();
547539 if (this ->inletsConnected [0 ] && static_cast <ofTexture *>(_inletParams[0 ])->isAllocated ()){
548540
549- warpedTexture->begin ();
550- ofClear (0 ,0 ,0 ,255 );
551- ofSetColor (255 );
552- static_cast <ofTexture *>(_inletParams[0 ])->draw (0 ,0 ,this ->output_width ,this ->output_height );
553- warpedTexture->end ();
554-
555541 ofSetColor (255 );
556542 if (useMapping && isFullscreen){
557- warpController->getWarp (0 )->draw (warpedTexture-> getTexture ( ));
543+ warpController->getWarp (0 )->draw (* static_cast <ofTexture *>(_inletParams[ 0 ] ));
558544 }else {
559- warpedTexture ->draw (thposX, thposY, thdrawW, thdrawH);
545+ static_cast <ofTexture *>(_inletParams[ 0 ]) ->draw (thposX, thposY, thdrawW, thdrawH);
560546 }
561- }else {
562- ofSetColor (0 );
563- ofDrawRectangle (posX, posY, drawW, drawH);
564547 }
565548 ofPopStyle ();
566549
@@ -582,40 +565,19 @@ void OutputWindow::resetOutputResolution(){
582565 this ->output_width = temp_width;
583566 this ->output_height = temp_height;
584567
585- _inletParams[0 ] = new ofTexture ();
586- static_cast <ofTexture *>(_inletParams[0 ])->allocate (this ->output_width ,this ->output_height ,GL_RGBA32F_ARB);
587-
588- warpedTexture = new ofFbo ();
589- warpedTexture->allocate (this ->output_width ,this ->output_height ,GL_RGBA32F_ARB,4 );
590- warpedTexture->begin ();
591- ofClear (0 ,0 ,0 ,255 );
592- warpedTexture->end ();
593-
594- if (static_cast <ofTexture *>(_inletParams[0 ])->isAllocated ()){
595- this ->setCustomVar (static_cast <float >(this ->output_width )," OUTPUT_WIDTH" );
596- this ->setCustomVar (static_cast <float >(this ->output_height )," OUTPUT_HEIGHT" );
597- this ->saveConfig (false );
598-
599- asRatio = reduceToAspectRatio (this ->output_width ,this ->output_height );
568+ this ->setCustomVar (static_cast <float >(this ->output_width )," OUTPUT_WIDTH" );
569+ this ->setCustomVar (static_cast <float >(this ->output_height )," OUTPUT_HEIGHT" );
570+ this ->saveConfig (false );
600571
601- if (!isFullscreen){
602- window_asRatio = reduceToAspectRatio (window->getWidth (),window->getHeight ());
603- scaleTextureToWindow (window->getWidth (),window->getHeight ());
604- }else {
605- window_asRatio = reduceToAspectRatio (window->getScreenSize ().x ,window->getScreenSize ().y );
606- scaleTextureToWindow (window->getScreenSize ().x ,window->getScreenSize ().y );
607- }
572+ if (!isFullscreen){
573+ scaleTextureToWindow (static_cast <ofTexture *>(_inletParams[0 ])->getWidth (), static_cast <ofTexture *>(_inletParams[0 ])->getHeight (), window->getWidth (),window->getHeight ());
574+ }else {
575+ scaleTextureToWindow (static_cast <ofTexture *>(_inletParams[0 ])->getWidth (), static_cast <ofTexture *>(_inletParams[0 ])->getHeight (), window->getScreenSize ().x ,window->getScreenSize ().y );
576+ }
608577
609- warpController = new ofxWarpController ();
610- shared_ptr<ofxWarpPerspectiveBilinear> warp = warpController->buildWarp <ofxWarpPerspectiveBilinear>();
611- warp->setSize (this ->output_width ,this ->output_height );
612- warp->setEdges (glm::vec4 (this ->getCustomVar (" EDGE_LEFT" ), this ->getCustomVar (" EDGE_TOP" ), this ->getCustomVar (" EDGE_RIGHT" ), this ->getCustomVar (" EDGE_BOTTOM" )));
613- warp->setLuminance (this ->getCustomVar (" EDGES_LUMINANCE" ));
614- warp->setGamma (this ->getCustomVar (" EDGES_GAMMA" ));
615- warp->setExponent (this ->getCustomVar (" EDGES_EXPONENT" ));
578+ warpController->getWarp (0 )->setSize (this ->output_width ,this ->output_height );
616579
617- ofLog (OF_LOG_NOTICE," %s: RESOLUTION CHANGED TO %ix%i" ,this ->name .c_str (),this ->output_width ,this ->output_height );
618- }
580+ ofLog (OF_LOG_NOTICE," %s: RESOLUTION CHANGED TO %ix%i" ,this ->name .c_str (),this ->output_width ,this ->output_height );
619581 }
620582
621583}
@@ -760,8 +722,9 @@ void OutputWindow::mouseScrolled(ofMouseEventArgs &e){
760722
761723// --------------------------------------------------------------
762724void OutputWindow::windowResized (ofResizeEventArgs &e){
763- window_asRatio = reduceToAspectRatio (window->getWidth (),window->getHeight ());
764- scaleTextureToWindow (window->getWidth (),window->getHeight ());
725+ if (static_cast <ofTexture *>(_inletParams[0 ])->isAllocated ()){
726+ scaleTextureToWindow (static_cast <ofTexture *>(_inletParams[0 ])->getWidth (), static_cast <ofTexture *>(_inletParams[0 ])->getHeight (), e.width ,e.height );
727+ }
765728
766729 this ->setCustomVar (window->getWindowPosition ().x ," OUTPUT_POSX" );
767730 this ->setCustomVar (window->getWindowPosition ().y ," OUTPUT_POSY" );
0 commit comments