1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2006 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
39 //---------------------------------------------------------------------------
41 //---------------------------------------------------------------------------
46 #include "OSGConfig.h"
48 #include "OSGCSMPassiveWindow.h"
49 #include "OSGCSMPassiveWinClearOp.h"
51 #include "OSGPassiveWindow.h"
52 #include "OSGComplexSceneManager.h"
57 // Documentation for this class is emitted in the
58 // OSGCSMPassiveWindowBase.cpp file.
59 // To modify it, please change the .fcd file (OSGCSMPassiveWindow.fcd) and
60 // regenerate the base file.
62 /***************************************************************************\
64 \***************************************************************************/
66 bool CSMPassiveWindow::_bGLUTInitialized
= false;
67 CSMPassiveWindow
*CSMPassiveWindow::_pPassiveWindow
= NULL
;
69 /***************************************************************************\
71 \***************************************************************************/
73 void CSMPassiveWindow::initMethod(InitPhase ePhase
)
75 Inherited::initMethod(ePhase
);
77 if(ePhase
== TypeObject::SystemPost
)
83 void CSMPassiveWindow::csmGlutKeyHandler(UChar8 key
,
91 glutKeyboardFunc (NULL
);
92 glutReshapeFunc (NULL
);
93 // glutDisplayFunc (NULL);
95 glutMotionFunc (NULL
);
98 ComplexSceneManager::the()->terminate();
107 ComplexSceneManager::the()->key(x
,
109 CSMKeyData::ButtonDown
,
115 void CSMPassiveWindow::csmGlutReshapeHandler(Int32 w
,
119 w
* _pPassiveWindow
->getViewportScale()[0],
120 h
* _pPassiveWindow
->getViewportScale()[1]);
122 if(_pPassiveWindow
->getViewportScale()[0] < 1.0 ||
123 _pPassiveWindow
->getViewportScale()[1] < 1.0 )
126 w
* _pPassiveWindow
->getViewportScale()[0],
127 h
* _pPassiveWindow
->getViewportScale()[1]);
129 glEnable(GL_SCISSOR_TEST
);
133 glDisable(GL_SCISSOR_TEST
);
136 _pPassiveWindow
->reshape(w
, h
);
141 void CSMPassiveWindow::csmGlutFrameHandler(void)
143 if(_pPassiveWindow
->getClearOp() != NULL
)
145 _pPassiveWindow
->getClearOp()->execute(_pPassiveWindow
);
149 glClearColor(0.2, 0.2, 0.5, 0.0);
150 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
153 ComplexSceneManager::the()->frame();
155 Thread::getCurrentChangeList()->commitChangesAndClear();
157 if(_pPassiveWindow
->getClearOp() != NULL
)
159 _pPassiveWindow
->getClearOp()->postDraw(_pPassiveWindow
);
165 void CSMPassiveWindow::csmGlutMouseHandler(Int32 iButton
,
170 _pPassiveWindow
->mouse(iButton
,
172 1 | (glutGetModifiers() << 1),
177 void CSMPassiveWindow::csmGlutMouseMotionHandler(Int32 x
,
180 _pPassiveWindow
->motion(x
, y
, 1 | (glutGetModifiers() << 1));
184 /***************************************************************************\
186 \***************************************************************************/
188 /*-------------------------------------------------------------------------*\
190 \*-------------------------------------------------------------------------*/
192 /*----------------------- constructors & destructors ----------------------*/
194 CSMPassiveWindow::CSMPassiveWindow(void) :
200 CSMPassiveWindow::CSMPassiveWindow(const CSMPassiveWindow
&source
) :
206 CSMPassiveWindow::~CSMPassiveWindow(void)
210 void CSMPassiveWindow::terminateGLContext(void)
214 _pWindow
->terminate();
217 glutDestroyWindow(_iGlutWinId
);
220 /*----------------------------- class specific ----------------------------*/
222 void CSMPassiveWindow::changed(ConstFieldMaskArg whichField
,
226 Inherited::changed(whichField
, origin
, details
);
229 void CSMPassiveWindow::dump( UInt32
,
230 const BitVector
) const
232 SLOG
<< "Dump CSMPassiveWindow NI" << std::endl
;
235 bool CSMPassiveWindow::init(void)
237 if(_bGLUTInitialized
== false)
240 const Char8
*argv
[] = { "testCSM-Passive" };
242 glutInit(&argc
, const_cast<Char8
**>(argv
));
245 UInt32 uiDisplayMode
= (GLUT_RGBA
|
252 if(_pVSCWindow
->stereo() == true)
254 uiDisplayMode
|= GLUT_STEREO
;
258 OSG::PassiveWindowUnrecPtr pPWindow
= OSG::PassiveWindow::create();
263 glutInitDisplayMode(uiDisplayMode
);
265 if(this->getXPos() > 0.f
&& this->getYPos() > 0.f
)
267 glutInitWindowPosition(Int32(this->getXPos()),
268 Int32(this->getYPos()));
271 if(this->getXSize() > 0.f
&& this->getYSize() > 0.f
)
273 glutInitWindowSize(Int32(this->getXSize()),
274 Int32(this->getYSize()));
277 _iGlutWinId
= glutCreateWindow("OpenSG - CSM");
279 // pGLUTWindow->setGlutId(iWinId);
281 if(this->getXSize() > 0.f
&& this->getYSize() > 0.f
)
283 pPWindow
->resize(Int32(this->getXSize()),
284 Int32(this->getYSize()));
287 if(ComplexSceneManager::the() != NULL
)
288 ComplexSceneManager::the()->setMainloop(glutMainLoop
);
291 if(_pVSCWindow
->getXSize () < 0.f
&&
292 _pVSCWindow
->getYSize () < 0.f
&&
293 _pVSCWindow
->getDecorEnabled() == false)
300 _pPassiveWindow
= this;
302 if(_bGLUTInitialized
== false)
304 _bGLUTInitialized
= true;
306 // _pFirstWindow = this;
308 glutKeyboardFunc (csmGlutKeyHandler
);
309 // glutVisibilityFunc(vscGlutVisHandler );
310 glutReshapeFunc (csmGlutReshapeHandler
);
311 glutDisplayFunc (csmGlutFrameHandler
);
312 glutMouseFunc (csmGlutMouseHandler
);
313 glutMotionFunc (csmGlutMouseMotionHandler
);
314 glutIdleFunc (csmGlutFrameHandler
);
320 OSG::IndentFileOutStream
outFileStream("/tmp/window.osg");
324 std::cerr
<< "STARTING PRINTOUT:" << std::endl
;
326 OSG::OSGWriter
writer(outFileStream
, 4);
328 writer
.write(_pOSGWindow
);
330 outFileStream
.close();
336 // pPWindow->activate();