1 // #define FRAMEINTERLEAVE
7 #include "OSGTransform.h"
10 #include "OSGClusterWindow.h"
11 #include "OSGSceneFileHandler.h"
12 #include "OSGDirectionalLight.h"
13 #include "OSGSimpleGeometry.h"
14 #include "OSGCamera.h"
15 #include "OSGViewport.h"
16 #include "OSGPerspectiveCamera.h"
17 #include "OSGSolidBackground.h"
18 #include "OSGGradientBackground.h"
19 #include "OSGTrackball.h"
20 #include "OSGVolumeDraw.h"
21 #include "OSGGLUTWindow.h"
22 #include "OSGMultiDisplayWindow.h"
23 #include "OSGBalancedMultiWindow.h"
24 #include "OSGSortFirstWindow.h"
25 #include "OSGChunkMaterial.h"
26 #include "OSGSimpleMaterial.h"
27 #include "OSGPolygonChunk.h"
28 #include "OSGGeoFunctions.h"
29 #include "OSGMaterialGroup.h"
30 #include "OSGSortLastWindow.h"
31 #include "OSGImageComposer.h"
32 #include "OSGProxyGroup.h"
33 #ifdef FRAMEINTERLEAVE
34 #include "OSGFrameInterleaveWindow.h"
36 #include "OSGShearedStereoCameraDecorator.h"
37 #include "OSGNameAttachment.h"
38 #include "OSGColorBufferViewport.h"
40 #include "OSGPipelineComposer.h"
41 #include "OSGBinarySwapComposer.h"
42 #include "OSGRenderAction.h"
48 int winwidth
=300, winheight
=300;
51 OSG::TransformRecPtr cam_trans
;
52 //OSG::PerspectiveCameraRecPtr cam;
53 OSG::ClusterWindowRecPtr clusterWindow
;
54 OSG::RenderActionRefPtr ract
;
55 OSG::GLUTWindowRecPtr clientWindow
;
56 OSG::SortFirstWindowRecPtr sortfirst
;
57 OSG::SortLastWindowRecPtr sortlast
;
58 #ifdef FRAMEINTERLEAVE
59 OSG::FrameInterleaveWindowRecPtr frameinterleave
;
61 OSG::MultiDisplayWindowRecPtr multidisplay
;
62 OSG::BalancedMultiWindowRecPtr balancedmultidisplay
;
68 float ca
=-1,cb
=-1,cc
=-1;
69 OSG::Int32 stereoMode
=0;
70 float eyedistance
=1,zeroparallax
=10;
71 int serverx
=-1,servery
=-1;
72 std::vector
<OSG::Quaternion
> animOri
;
73 std::vector
<OSG::Vec3f
> animPos
;
74 std::string animName
="animation.txt";
75 OSG::Real32 animTime
=0;
76 std::string serviceInterface
;
77 bool serviceInterfaceValid
= false;
78 std::string serviceAddress
;
79 bool serviceAddressValid
= false;
80 OSG::UInt32 interleave
=0;
81 OSG::Real32 _dsFactor
= 1.0; // scale down factor.
82 bool _enablecc
= true; // enable color correction.
83 OSG::PolygonChunkRecPtr polygonChunk
;
86 OSG::Time frame_time
=0;
87 OSG::UInt32 sum_positions
=0;
88 OSG::UInt32 sum_geometries
=0;
89 OSG::UInt32 sum_triangles
=0;
91 std::string connectionDestination
="";
92 std::string connectionInterface
="";
93 OSG::SolidBackgroundRecPtr bkgnd
;
94 OSG::Int32 subtilesize
=-1;
95 bool pipelinedBufferRead
= false;
102 clusterWindow
= NULL
;
106 #ifdef FRAMEINTERLEAVE
107 frameinterleave
= NULL
;
110 balancedmultidisplay
= NULL
;
117 /*! Simple show text function
119 void displayInfo(int x
, int y
)
124 void *font
= (void *) 2;
129 #ifdef OSG_DEBUG_OLD_C_CASTS
130 void *font
= glutBitmap9By15
;
132 void *font
= GLUT_BITMAP_9_BY_15
;
147 glPushAttrib(GL_ALL_ATTRIB_BITS
);
148 glDisable(GL_LIGHTING
);
149 glEnable(GL_COLOR_MATERIAL
);
152 glMatrixMode(GL_PROJECTION
);
155 gluOrtho2D(0,clientWindow
->getWidth(),0,clientWindow
->getHeight());
156 glDisable(GL_DEPTH_TEST
);
158 glBlendFunc(GL_SRC_ALPHA
,GL_ONE_MINUS_SRC_ALPHA
);
165 glColor4f(.1f
, .1f
, .7f
, .5f
);
171 glBegin(GL_LINE_LOOP
);
172 glColor3f(1.0, 1.0, 0.0);
179 glColor3f(1.0, 1.0, 0.0);
181 len
= int(strlen(text
));
182 for (i
= 0; i
< len
; i
++) {
189 glutBitmapCharacter(font
, text
[i
]);
192 glMatrixMode(GL_MODELVIEW
);
197 void prepareSceneGraph(OSG::Node
* const node
)
201 polygonChunk
= OSG::PolygonChunk::create();
205 OSG::NodeCore
*core
=node
->getCore();
208 OSG::Geometry
*geo
= dynamic_cast<OSG::Geometry
*>(core
);
211 OSG::Material
*mat
= geo
->getMaterial();
214 OSG::ChunkMaterial
*cmat
=
215 dynamic_cast<OSG::ChunkMaterial
*>(mat
);
216 if(cmat
->find(OSG::PolygonChunk::getClassType()) == NULL
)
218 cmat
->addChunk(polygonChunk
);
222 OSG::GeoVectorProperty
*positionsPtr
=geo
->getPositions();
223 if(positionsPtr
!= NULL
)
224 sum_positions
+= positionsPtr
->size32();
226 OSG::UInt32 triangle
=0;
229 OSG::UInt32 patches
=0;
230 calcPrimitiveCount(geo
,triangle
,line
,point
, patches
);
231 sum_triangles
+= triangle
;
232 // sum of geometry nodes
237 OSG::MaterialGroup
*matGrp
=
238 dynamic_cast<OSG::MaterialGroup
*>(core
);
241 OSG::Material
*mat
= matGrp
->getMaterial();
244 OSG::ChunkMaterial
*cmat
=
245 dynamic_cast<OSG::ChunkMaterial
*>(mat
);
246 if(cmat
->find(OSG::PolygonChunk::getClassType()) == NULL
)
248 cmat
->addChunk(polygonChunk
);
254 OSG::ProxyGroup
*proxy
= dynamic_cast<OSG::ProxyGroup
*>(core
);
257 sum_triangles
+= proxy
->getTriangles();
258 sum_positions
+= proxy
->getPositions();
259 sum_geometries
+= proxy
->getGeometries();
264 for(OSG::MFUnrecChildNodePtr::const_iterator nI
=node
->getMFChildren()->begin();
265 nI
!= node
->getMFChildren()->end();
268 prepareSceneGraph(*nI
);
274 OSG::Real32 ax
,ay
,az
,r
,x
,y
,z
;
275 FILE *file
=fopen(animName
.c_str(),"r");
281 while(fscanf(file
,"%f %f %f %f,%f %f %f",&ax
,&ay
,&az
,&r
,&x
,&y
,&z
)==7)
283 animOri
.push_back(OSG::Quaternion(OSG::Vec3f(ax
,ay
,az
),r
));
284 animPos
.push_back(OSG::Vec3f(x
,y
,z
));
293 // std::cout << glutGet(GLUT_WINDOW_WIDTH) << std::endl;
295 t
=-OSG::getSystemTime();
297 if(animate
&& animPos
.size()>1)
300 animTime
= frameCount
* (animPos
.size())/float(animLength
);
302 OSG::UInt32 i
=OSG::UInt32(animTime
);
303 OSG::Real32 a
=animTime
-i
;
307 if(i
+1 < animPos
.size())
309 v
= animPos
[i
] + (animPos
[i
+1] - animPos
[i
]) * a
;
310 q
= OSG::Quaternion::slerp(animOri
[i
],animOri
[i
+1],a
);
317 cam_trans
->editMatrix().setTranslate(v
[0],v
[1],v
[2]);
318 cam_trans
->editMatrix().setRotate(q
);
322 cam_trans
->editSFMatrix()->setValue( tball
.getFullTrackballMatrix() );
327 OSG::Thread::getCurrentChangeList()->commitChanges();
329 clusterWindow
->activate();
330 clusterWindow
->frameInit();
331 clusterWindow
->renderAllViewports(ract
);
333 clusterWindow
->renderNoFinish(ract
);
340 sprintf(text,"FPS: %12.1f",1.0/frame_time);
341 showText(10,70,text);
342 sprintf(text,"Positions: %12d",sum_positions);
343 showText(10,50,text);
344 sprintf(text,"Triangles: %12d",sum_triangles);
345 showText(10,30,text);
346 sprintf(text,"Geometries: %12d",sum_geometries);
347 showText(10,10,text);
352 clusterWindow
->swap();
353 clusterWindow
->frameExit();
355 clusterWindow
->frameFinish();
356 // clear changelist from prototypes
357 OSG::Thread::getCurrentChangeList()->clear();
359 catch(OSG_STDEXCEPTION_NAMESPACE::exception
&e
)
361 std::cout
<< e
.what() << std::endl
;
366 t
+=OSG::getSystemTime();
369 if(animate
&& animPos
.size()>1)
373 printf("Frame %8.3f %8.5f %8.3f\n",
378 if(frameCount
== animLength
)
397 void reshape( int width
, int height
)
399 printf("reshape %d %d\n",width
,height
);
400 glViewport(0, 0, width
, height
);
402 clientWindow
->resize( width
, height
);
407 void motion(int x
, int y
)
409 OSG::Real32 w
= clientWindow
->getWidth(), h
= clientWindow
->getHeight();
412 OSG::Real32 a
= -2. * ( lastx
/ w
- .5 ),
413 b
= -2. * ( .5 - lasty
/ h
),
414 c
= -2. * ( x
/ w
- .5 ),
415 d
= -2. * ( .5 - y
/ h
);
417 if ( mouseb
& ( 1 << GLUT_LEFT_BUTTON
) )
419 tball
.updateRotation( a
, b
, c
, d
);
421 else if ( mouseb
& ( 1 << GLUT_MIDDLE_BUTTON
) )
423 tball
.updatePosition( a
, b
, c
, d
);
425 else if ( mouseb
& ( 1 << GLUT_RIGHT_BUTTON
) )
427 tball
.updatePositionNeg( a
, b
, c
, d
);
434 void mouse(int button
, int state
, int x
, int y
)
440 case GLUT_LEFT_BUTTON
: break;
441 case GLUT_MIDDLE_BUTTON
:tball
.setAutoPosition(true);
443 case GLUT_RIGHT_BUTTON
: tball
.setAutoPositionNeg(true);
446 mouseb
|= 1 << button
;
448 else if ( state
== 1 )
452 case GLUT_LEFT_BUTTON
: break;
453 case GLUT_MIDDLE_BUTTON
:tball
.setAutoPosition(false);
455 case GLUT_RIGHT_BUTTON
: tball
.setAutoPositionNeg(false);
458 mouseb
&= ~(1 << button
);
465 void setHEyeWallParameter(OSG::Real32 dsFactor
, bool enablecc
)
467 static char str
[1024];
469 OSG::NameUnrecPtr parameters
= dynamic_cast<OSG::Name
*>(clusterWindow
->findAttachment(OSG::Name::getClassType()));
471 if(parameters
== NULL
)
473 parameters
= OSG::Name::create();
474 clusterWindow
->addAttachment(parameters
);
477 sprintf(str
, "downScale=%f colorCorrection=%d", dsFactor
, enablecc
);
478 parameters
->editFieldPtr()->getValue().assign(str
);
481 void key(unsigned char key
, int /*x*/, int /*y*/)
492 FILE *file
=fopen(animName
.c_str(),"w");
502 FILE *file
=fopen(animName
.c_str(),"a");
503 OSG::Matrix m
=cam_trans
->getMatrix();
504 OSG::Quaternion
q(m
);
505 OSG::Real32 ax
,ay
,az
,r
;
506 animPos
.push_back(OSG::Vec3f(m
[3][0],
509 animOri
.push_back(q
);
510 q
.getValueAsAxisRad(ax
,ay
,az
,r
);
511 fprintf(file
,"%f %f %f %f,%f %f %f\n",ax
,ay
,az
,r
,
522 FILE *file
=fopen((animName
+".wrl").c_str(),"w");
523 std::vector
<OSG::Quaternion
>::iterator qit
;
525 fprintf(file
,"DEF OriInter OrientationInterpolator {\n\tkey [");
526 for(size_t i
= 0; i
< animOri
.size(); ++i
)
528 fprintf(file
, "%f", i
/ OSG::Real32(animOri
.size() - 1) );
529 if(i
< animOri
.size() - 1)
532 fprintf(file
,"]\n\tkeyValue [");
533 for(qit
= animOri
.begin(); qit
!= animOri
.end(); ++qit
)
535 OSG::Real32 ax
,ay
,az
,r
;
536 (*qit
).getValueAsAxisRad(ax
,ay
,az
,r
);
538 fprintf(file
, "%f %f %f %f", ax
, ay
, az
, r
);
539 if(qit
< animOri
.end() - 1)
542 fprintf(file
,"]\n}\n\n");
544 std::vector
<OSG::Vec3f
>::iterator vit
;
546 fprintf(file
,"DEF PosInter PositionInterpolator {\n\tkey [");
547 for(size_t i
= 0; i
< animPos
.size(); ++i
)
549 fprintf(file
, "%f", i
/ OSG::Real32(animPos
.size() - 1) );
550 if(i
< animPos
.size() - 1)
553 fprintf(file
,"]\n\tkeyValue [");
554 for(vit
= animPos
.begin(); vit
!= animPos
.end(); ++vit
)
558 fprintf(file
, "%f %f %f, ", v
[0], v
[1], v
[2] );
560 fprintf(file
,"]\n}\n\n");
568 sortfirst
->setCompression("JPEG");
574 sortfirst
->setCompression("RLE");
580 sortfirst
->editCompression().erase();
584 showInfo
= !showInfo
;
587 if(polygonChunk
->getFrontMode() == GL_FILL
)
588 polygonChunk
->setFrontMode(GL_LINE
);
590 polygonChunk
->setFrontMode(GL_FILL
);
592 if(polygonChunk
->getBackMode() == GL_FILL
)
593 polygonChunk
->setBackMode(GL_LINE
);
595 polygonChunk
->setBackMode(GL_FILL
);
605 glutIdleFunc(display
);
613 while(root
->getNChildren())
622 setHEyeWallParameter(_dsFactor
, _enablecc
);
626 if(_dsFactor
<= 0.0f
)
628 setHEyeWallParameter(_dsFactor
, _enablecc
);
635 setHEyeWallParameter(_dsFactor
, _enablecc
);
638 if(bkgnd
->getColor()[0] == 0.0)
639 bkgnd
->setColor( OSG::Color3f(1,1,1) );
641 bkgnd
->setColor( OSG::Color3f(0,0,0) );
643 case 27: // should kill the clients here
653 void init(std::vector
<std::string
> &filenames
)
656 OSG::DirectionalLightUnrecPtr dl
;
658 OSG::BoxVolume volume
;
662 glEnable( GL_DEPTH_TEST
);
663 glEnable( GL_LIGHTING
);
664 glEnable( GL_LIGHT0
);
665 // GLint twoSide = 1;
666 // glLightModeliv(GL_LIGHT_MODEL_TWO_SIDE,&twoSide);
667 glPixelStorei( GL_UNPACK_ALIGNMENT
, 1 );
671 // beacon for camera and light
672 OSG::NodeUnrecPtr b1n
= OSG::Node::create();
673 OSG::GroupUnrecPtr b1
= OSG::Group::create();
677 OSG::NodeUnrecPtr t1n
= OSG::Node::create();
678 OSG::TransformUnrecPtr t1
= OSG::Transform::create();
680 t1n
->addChild( b1n
);
686 OSG::NodeUnrecPtr dlight
= OSG::Node::create();
687 dl
= OSG::DirectionalLight::create();
689 dlight
->setCore( dl
);
691 dl
->setAmbient( .3f
, .3f
, .3f
, 1 );
692 dl
->setDiffuse( 1, 1, 1, 1 );
693 dl
->setDirection(0,0,1);
697 root
= OSG::Node::create();
699 OSG::GroupUnrecPtr gr1
= OSG::Group::create();
701 root
->setCore( gr1
);
702 root
->addChild( t1n
);
703 root
->addChild( dlight
);
706 OSG::NodeUnrecPtr scene
= OSG::Node::create();
707 scene
->setCore(OSG::Group::create());
709 OSG::NodeUnrecPtr file
;
710 for(i
=0;i
<filenames
.size();i
++)
712 file
= OSG::SceneFileHandler::the()->read(filenames
[i
].c_str(),0);
714 scene
->addChild(file
);
716 std::cerr
<< "Couldn't load file, ignoring " << filenames
[i
] << std::endl
;
718 if ( filenames
.size()==0 )
720 file
= OSG::makeTorus( .5, 2, 16, 16 );
721 scene
->addChild(file
);
722 // scene->addChild(makeBox(.6,.6,.6,5,5,5));
725 prepareSceneGraph(scene
);
727 OSG::Thread::getCurrentChangeList()->commitChanges();
729 scene
->invalidateVolume();
730 scene
->updateVolume();
731 volume
=scene
->getVolume();
732 volume
.getBounds(min
,max
);
742 OSG::NodeUnrecPtr node
;
743 OSG::NodeUnrecPtr geoNode
;
744 OSG::TransformUnrecPtr trans
;
745 for(x
=-ca
/2.0 ; x
<ca
/2.0 ; x
++)
746 for(y
=-cb
/2.0 ; y
<cb
/2.0 ; y
++)
747 for(z
=-cc
/2.0 ; z
<cc
/2.0 ; z
++)
749 trans
=OSG::Transform::create();
750 node
=OSG::Node::create();
752 node
->setCore(trans
);
753 trans
->editMatrix().setTranslate(
757 geoNode
= OSG::cloneTree(scene
);
758 geoNode
->editSFVolume()->getValue() = scene
->getSFVolume()->getValue();
759 geoNode
->editVolume(false).setValid(true);
760 node
->addChild( geoNode
);
761 dlight
->addChild(node
);
766 dlight
->addChild(scene
);
771 sum_geometries
*=OSG::UInt32(ca
*cb
*cc
);
772 sum_triangles
*=OSG::UInt32(ca
*cb
*cc
);
773 sum_positions
*=OSG::UInt32(ca
*cb
*cc
);
776 OSG::Thread::getCurrentChangeList()->commitChanges();
778 // dlight->invalidateVolume();
779 printf("update Volume\n");
780 dlight
->updateVolume();
781 printf("update Volume OK\n");
783 // should check first. ok for now.
784 const OSG::BoxVolume
&vol
= dlight
->getVolume();
788 vol
.getBounds(min
, max
);
789 vol
.getCenter(center
);
793 std::cout
<< "Volume: from " << min
<< " to " << max
<< std::endl
;
794 std::cout
<< "Center: " << center
<< std::endl
;
798 OSG::PerspectiveCameraUnrecPtr cam
= OSG::PerspectiveCamera::create();
799 cam
->setBeacon( b1n
);
800 cam
->setFov( OSG::osgDegree2Rad( 60 ) );
802 cam
->setFar( 50000 );
805 bkgnd
= OSG::SolidBackground::create();
806 bkgnd
->setColor( OSG::Color3f(0,0,0) );
807 // bkgnd->setColor( OSG::Color3f(.1,.1,.6) );
808 // bkgnd->setColor( OSG::Color3f(1,1,1) );
811 OSG::ViewportUnrecPtr vp1
;
812 OSG::ViewportUnrecPtr vp2
;
815 vp1
= OSG::Viewport::create();
816 vp1
->setCamera ( cam
);
817 vp1
->setBackground( bkgnd
);
818 vp1
->setRoot ( root
);
819 vp1
->setSize ( 0,0, 1,1 );
823 vp2
= OSG::Viewport::create();
824 vp2
->setCamera ( cam
);
825 vp2
->setBackground( bkgnd
);
826 vp2
->setRoot ( root
);
827 vp2
->setSize ( .1f
, .55f
, .7f
,.95f
);
830 else if(stereoMode
== 1)
832 OSG::ShearedStereoCameraDecoratorUnrecPtr deco
;
834 deco
=OSG::ShearedStereoCameraDecorator::create();
835 deco
->setLeftEye(true);
836 deco
->setEyeSeparation(eyedistance
);
837 deco
->setDecoratee(cam
);
838 deco
->setZeroParallaxDistance(zeroparallax
);
839 vp1
= OSG::Viewport::create();
840 vp1
->setCamera ( deco
);
841 vp1
->setBackground( bkgnd
);
842 vp1
->setRoot ( root
);
843 vp1
->setSize ( 0,0, .5,1 );
845 deco
=OSG::ShearedStereoCameraDecorator::create();
846 deco
->setLeftEye(false);
847 deco
->setEyeSeparation(eyedistance
);
848 deco
->setDecoratee(cam
);
849 deco
->setZeroParallaxDistance(zeroparallax
);
850 vp2
= OSG::Viewport::create();
851 vp2
->setCamera ( deco
);
852 vp2
->setBackground( bkgnd
);
853 vp2
->setRoot ( root
);
854 vp2
->setSize ( .5,0,1,1 );
856 else if(stereoMode
== 2)
858 OSG::ShearedStereoCameraDecoratorUnrecPtr deco
;
860 deco
=OSG::ShearedStereoCameraDecorator::create();
861 deco
->setLeftEye(true);
862 deco
->setEyeSeparation(eyedistance
);
863 deco
->setDecoratee(cam
);
864 deco
->setZeroParallaxDistance(zeroparallax
);
866 OSG::ColorBufferViewportUnrecPtr cvp1
=
867 OSG::ColorBufferViewport::create();
868 cvp1
->setCamera ( deco
);
869 cvp1
->setBackground( bkgnd
);
870 cvp1
->setRoot ( root
);
871 cvp1
->setSize ( 0,0, 1,1 );
872 cvp1
->setRed(GL_FALSE
);
873 cvp1
->setGreen(GL_TRUE
);
874 cvp1
->setBlue(GL_TRUE
);
875 cvp1
->setAlpha(GL_TRUE
);
879 deco
=OSG::ShearedStereoCameraDecorator::create();
880 deco
->setLeftEye(false);
881 deco
->setEyeSeparation(eyedistance
);
882 deco
->setDecoratee(cam
);
883 deco
->setZeroParallaxDistance(zeroparallax
);
885 OSG::ColorBufferViewportUnrecPtr cvp2
=
886 OSG::ColorBufferViewport::create();
887 cvp2
->setCamera ( deco
);
888 cvp2
->setBackground( bkgnd
);
889 cvp2
->setRoot ( root
);
890 cvp2
->setSize ( 0,0,1,1 );
891 cvp2
->setRed(GL_TRUE
);
892 cvp2
->setGreen(GL_FALSE
);
893 cvp2
->setBlue(GL_FALSE
);
894 cvp2
->setAlpha(GL_FALSE
);
899 glGetIntegerv( GL_VIEWPORT
, glvp
);
901 if(serverx
>0 && servery
>0)
902 clusterWindow
->setSize( serverx
, servery
);
904 clusterWindow
->setSize( glvp
[2], glvp
[3] );
905 clusterWindow
->addPort( vp1
);
907 if(multiport
|| stereoMode
> 0)
908 clusterWindow
->addPort( vp2
);
910 if(serviceInterfaceValid
== true)
912 clusterWindow
->setServiceInterface(serviceInterface
);
914 fprintf(stderr
, "tcclient use if %s\n", serviceInterface
.c_str());
917 if(serviceAddressValid
== true)
919 clusterWindow
->setServiceAddress(serviceAddress
);
921 fprintf(stderr
, "tcclient use ba %s\n", serviceAddress
.c_str());
926 OSG::Vec3f
pos(min
[0] + ((max
[0] - min
[0]) * 0.5),
927 min
[1] + ((max
[1] - min
[1]) * 0.5),
928 max
[2] + ( max
[2] - min
[2] ) * 1.5 );
930 float scale
= (max
[2] - min
[2] + max
[1] - min
[1] + max
[0] - min
[0]) / 6;
932 tball
.setMode( OSG::Trackball::OSGObject
);
933 tball
.setStartPosition( pos
, true );
934 tball
.setSum( true );
935 tball
.setTranslationMode( OSG::Trackball::OSGFree
);
936 tball
.setTranslationScale(scale
);
937 tball
.setRotationCenter(center
);
938 tball
.setTranslationGen(OSG::Trackball::OSGAbsoluteTranslation
);
941 std::cout
<< size
.length() << std::endl
;
942 cam
->setFar (size
.length() * 100.0);
943 cam
->setNear(size
.length() * 100.0 / 100000.0);
946 int doMain(int argc
,char **argv
)
950 std::vector
<std::string
> filenames
;
951 std::vector
<std::string
> servers
;
952 std::string connectionType
= "StreamSock";
953 std::string connectionParameters
;
957 bool clientRendering
=true;
960 std::string composerType
="";
961 std::string autostart
;
965 if(strlen(argv
[i
])>1 && argv
[i
][0]=='-')
970 opt
= argv
[i
][2] ? argv
[i
]+2 : argv
[++i
];
971 connectionParameters
= opt
;
972 printf("connectionParameters: '%s'\n", connectionParameters
.c_str());
975 opt
= argv
[i
][2] ? argv
[i
]+2 : argv
[++i
];
979 opt
= argv
[i
][2] ? argv
[i
]+2 : argv
[++i
];
980 if(sscanf(opt
,"%f,%f,%f",&ca
,&cb
,&cc
)!=3)
982 std::cout
<< "Copy opton -D x,y,z" << std::endl
;
987 opt
= argv
[i
][2] ? argv
[i
]+2 : argv
[++i
];
988 serviceInterface
.assign(opt
);
989 serviceInterfaceValid
= true;
992 opt
= argv
[i
][2] ? argv
[i
]+2 : argv
[++i
];
993 serviceAddress
.assign(opt
);
994 serviceAddressValid
= true;
997 opt
= argv
[i
][2] ? argv
[i
]+2 : argv
[++i
];
998 filenames
.push_back(opt
);
999 printf("<%s>\n",opt
);
1002 connectionType
="Multicast";
1005 opt
= argv
[i
][2] ? argv
[i
]+2 : argv
[++i
];
1006 if(sscanf(opt
,"%d,%d",&rows
,&cols
) != 2)
1007 sscanf(opt
,"%d",&rows
);
1010 opt
= argv
[i
][2] ? argv
[i
]+2 : argv
[++i
];
1011 subtilesize
=atoi(opt
);
1013 #ifdef FRAMEINTERLEAVE
1015 opt
= argv
[i
][2] ? argv
[i
]+2 : argv
[++i
];
1016 interleave
=atoi(opt
);
1035 while(argv
[i
][lpos
])
1037 if(argv
[i
][lpos
] == 'B')
1038 composerType
= "BinarySwapComposer";
1039 if(argv
[i
][lpos
] == 'P')
1040 composerType
= "PipelineComposer";
1041 if(argv
[i
][lpos
] == 'S')
1042 composerType
= "SepiaComposer";
1043 if(argv
[i
][lpos
] == 'p')
1044 pipelinedBufferRead
= true;
1065 opt
= argv
[i
][2] ? argv
[i
]+2 : argv
[++i
];
1066 sscanf(opt
,"%f",&eyedistance
);
1069 opt
= argv
[i
][2] ? argv
[i
]+2 : argv
[++i
];
1070 sscanf(opt
,"%f",&zeroparallax
);
1073 clientRendering
=false;
1079 opt
= argv
[i
][2] ? argv
[i
]+2 : argv
[++i
];
1080 sscanf(opt
,"%d",&serverx
);
1083 opt
= argv
[i
][2] ? argv
[i
]+2 : argv
[++i
];
1084 sscanf(opt
,"%d",&servery
);
1087 opt
= argv
[i
][2] ? argv
[i
]+2 : argv
[++i
];
1093 opt
= argv
[i
][2] ? argv
[i
]+2 : argv
[++i
];
1094 if(sscanf(opt
,"%d,%d",&animLoops
,&animLength
) != 2)
1097 if(sscanf(opt
,"%d",&animLoops
) != 1)
1104 opt
= argv
[i
][2] ? argv
[i
]+2 : argv
[++i
];
1105 if(sscanf(opt
,"%d,%d,%d,%d",
1106 &winwidth
,&winheight
,&winx
,&winy
) != 4)
1107 sscanf(opt
,"%d,%d",&winwidth
,&winheight
);
1110 opt
= argv
[i
][2] ? argv
[i
]+2 : argv
[++i
];
1111 connectionDestination
= opt
;
1114 opt
= argv
[i
][2] ? argv
[i
]+2 : argv
[++i
];
1115 connectionInterface
= opt
;
1118 std::cout
<< argv
[0]
1119 << "-ffile -m -rrows[,cols] -C -M"
1121 std::cout
<< "-m use multicast" << std::endl
1122 << "-G multicast group" << std::endl
1123 << "-i interface" << std::endl
1124 << "-b service interface" << std::endl
1125 << "-M multi display" << std::endl
1126 #ifdef FRAMEINTERLEAVE
1127 << "-I frame interleave" << std::endl
1129 << "-r number of display rows" << std::endl
1130 << "-C compose" << std::endl
1131 << "-F sort-first" << std::endl
1132 << "-L sort-last" << std::endl
1133 << "-h this msg" << std::endl
1134 << "-s stereo" << std::endl
1135 << "-c red/cyan stereo" << std::endl
1136 << "-e eye distance" << std::endl
1137 << "-z zero parallax" << std::endl
1138 << "-d disable client rendering"<<std::endl
1139 << "-v use two viewports" << std::endl
1140 << "-x server x resolution" << std::endl
1141 << "-y server y resolution" << std::endl
1142 << "-t subtile size for img composition" << std::endl
1143 << "-D x,y,z duplicate geometry" << std::endl
1144 << "-A Autostart command" << std::endl
1145 << "-o connection parameter string e.g. \"TTL=8\"" << std::endl
;
1151 servers
.push_back(argv
[i
]);
1155 OSG::ChangeList::setReadWriteDefault(true);
1156 OSG::osgInit(argc
, argv
);
1157 glutInit(&argc
, argv
);
1158 glutInitDisplayMode( GLUT_RGB
| GLUT_DEPTH
| GLUT_DOUBLE
);
1159 if(winx
>=0 && winy
>=0)
1160 glutInitWindowPosition(winx
,winy
);
1161 glutInitWindowSize(winwidth
,winheight
);
1162 winid
= glutCreateWindow("OpenSG Cluster Client");
1163 glutKeyboardFunc(key
);
1164 glutReshapeFunc(reshape
);
1165 glutDisplayFunc(display
);
1167 glutIdleFunc(display
);
1168 glutMouseFunc(mouse
);
1169 glutMotionFunc(motion
);
1170 ract
= OSG::RenderAction::create();
1171 #ifdef OSG_OLD_RENDER_ACTION
1172 ract
->setSortTrans(true);
1173 ract
->setZWriteTrans(true);
1174 ract
->setLocalLights(true);
1175 ract
->setCorrectTwoSidedLighting(true);
1178 // clear changelist from prototypes
1179 OSG::Thread::getCurrentChangeList()->clear();
1181 // create cluster window
1185 multidisplay
=OSG::MultiDisplayWindow::create();
1186 clusterWindow
=multidisplay
;
1189 balancedmultidisplay
=OSG::BalancedMultiWindow::create();
1190 clusterWindow
=balancedmultidisplay
;
1193 sortfirst
=OSG::SortFirstWindow::create();
1195 sortfirst
->setCompose(true);
1197 sortfirst
->setCompose(false);
1198 clusterWindow
=sortfirst
;
1201 sortlast
=OSG::SortLastWindow::create();
1202 if(!composerType
.empty())
1204 OSG::FieldContainerUnrecPtr fcPtr
=
1205 OSG::FieldContainerFactory::the()->
1206 createContainer(composerType
.c_str());
1207 OSG::ImageComposer
*icPtr
=
1208 dynamic_cast<OSG::ImageComposer
*>(fcPtr
.get());
1212 if(dynamic_cast<OSG::PipelineComposer
*>(icPtr
) != NULL
)
1215 dynamic_cast<OSG::PipelineComposer
*>(icPtr
)->setTileSize(subtilesize
);
1216 dynamic_cast<OSG::PipelineComposer
*>(icPtr
)->setPipelined(pipelinedBufferRead
);
1218 if(dynamic_cast<OSG::BinarySwapComposer
*>(icPtr
) != NULL
)
1221 dynamic_cast<OSG::BinarySwapComposer
*>(icPtr
)->setTileSize(subtilesize
);
1223 icPtr
->setStatistics(info
);
1224 // icPtr->setShort(false);
1225 sortlast
->setComposer(icPtr
);
1228 clusterWindow
=sortlast
;
1230 #ifdef FRAMEINTERLEAVE
1232 frameinterleave
=OSG::FrameInterleaveWindow::create();
1233 clusterWindow
=frameinterleave
;
1235 frameinterleave
->setCompose(true);
1237 frameinterleave
->setCompose(false);
1241 sortfirst
=OSG::SortFirstWindow::create();
1242 sortfirst
->setCompose(false);
1243 clusterWindow
=sortfirst
;
1247 if(!autostart
.empty())
1248 clusterWindow
->editMFAutostart()->push_back(autostart
);
1250 for(i
=0 ; i
<int(servers
.size()) ; ++i
)
1251 clusterWindow
->editMFServers()->push_back(servers
[i
]);
1253 cols
= clusterWindow
->getMFServers()->size32() / rows
;
1257 multidisplay
->setHServers(cols
);
1258 multidisplay
->setVServers(rows
);
1261 balancedmultidisplay
->setHServers(cols
);
1262 balancedmultidisplay
->setVServers(rows
);
1263 // balancedmultidisplay->setShowBalancing(true);
1264 // balancedmultidisplay->setShowBalancing(info);
1267 #ifdef FRAMEINTERLEAVE
1268 clusterWindow
->setInterleave(interleave
);
1271 // create client window
1272 clientWindow
=OSG::GLUTWindow::create();
1273 // glutReshapeWindow(800,600);
1274 glutReshapeWindow(winwidth
,winheight
);
1275 clientWindow
->setGlutId(winid
);
1276 clientWindow
->init();
1282 clusterWindow
->setConnectionType(connectionType
);
1283 // needs to be called before init()!
1284 clusterWindow
->setConnectionParams(connectionParameters
);
1287 clusterWindow
->setClientWindow(clientWindow
);
1289 clusterWindow
->setConnectionDestination(connectionDestination
);
1290 clusterWindow
->setConnectionInterface(connectionInterface
);
1291 clusterWindow
->init();
1293 clusterWindow
->resize(serverx
,servery
);
1295 clusterWindow
->resize(winwidth
,winheight
);
1296 clientWindow
->resize(winwidth
,winheight
);
1298 // OSG::FieldContainerFactory::the()->dump();
1300 OSG::commitChanges();
1307 int main(int argc
,char **argv
)