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 "OSGCSMGLUTWindow.h"
50 #include "OSGGLUTWindow.h"
51 #include "OSGComplexSceneManager.h"
55 // Documentation for this class is emitted in the
56 // OSGCSMGLUTWindowBase.cpp file.
57 // To modify it, please change the .fcd file (OSGCSMGLUTWindow.fcd) and
58 // regenerate the base file.
60 /***************************************************************************\
62 \***************************************************************************/
64 bool CSMGLUTWindow::_bGLUTInitialized
= false;
65 CSMGLUTWindow
*CSMGLUTWindow::_pGLUTWindow
= NULL
;
67 /***************************************************************************\
69 \***************************************************************************/
71 void CSMGLUTWindow::initMethod(InitPhase ePhase
)
73 Inherited::initMethod(ePhase
);
75 if(ePhase
== TypeObject::SystemPost
)
80 void CSMGLUTWindow::csmGlutKeyHandler(UChar8 key
,
88 glutKeyboardFunc (NULL
);
89 glutReshapeFunc (NULL
);
90 // glutDisplayFunc (NULL);
92 glutMotionFunc (NULL
);
95 ComplexSceneManager::the()->terminate();
104 ComplexSceneManager::the()->key(x
,
106 CSMKeyData::ButtonDown
,
112 void CSMGLUTWindow::csmGlutReshapeHandler(Int32 w
,
115 _pGLUTWindow
->reshape(w
, h
);
120 void CSMGLUTWindow::csmGlutFrameHandler(void)
122 ComplexSceneManager::the()->frame();
124 Thread::getCurrentChangeList()->commitChangesAndClear();
127 void CSMGLUTWindow::csmGlutMouseHandler(Int32 iButton
,
132 _pGLUTWindow
->mouse(iButton
,
134 1 | (glutGetModifiers() << 1),
139 void CSMGLUTWindow::csmGlutMouseMotionHandler(Int32 x
,
142 _pGLUTWindow
->motion(x
, y
, 1 | (glutGetModifiers() << 1));
145 /***************************************************************************\
147 \***************************************************************************/
149 /*-------------------------------------------------------------------------*\
151 \*-------------------------------------------------------------------------*/
153 /*----------------------- constructors & destructors ----------------------*/
155 CSMGLUTWindow::CSMGLUTWindow(void) :
161 CSMGLUTWindow::CSMGLUTWindow(const CSMGLUTWindow
&source
) :
167 CSMGLUTWindow::~CSMGLUTWindow(void)
171 void CSMGLUTWindow::terminateGLContext(void)
175 _pWindow
->terminate();
178 glutDestroyWindow(_iGlutWinId
);
181 /*----------------------------- class specific ----------------------------*/
183 void CSMGLUTWindow::changed(ConstFieldMaskArg whichField
,
187 Inherited::changed(whichField
, origin
, details
);
190 void CSMGLUTWindow::dump( UInt32
,
191 const BitVector
) const
193 SLOG
<< "Dump CSMGLUTWindow NI" << std::endl
;
196 bool CSMGLUTWindow::init(void)
198 if(_bGLUTInitialized
== false)
201 const Char8
*argv
[] = { "testCSM" };
203 glutInit(&argc
, const_cast<Char8
**>(argv
));
206 UInt32 uiDisplayMode
= (GLUT_RGBA
|
213 if(_pVSCWindow
->stereo() == true)
215 uiDisplayMode
|= GLUT_STEREO
;
219 OSG::GLUTWindowUnrecPtr pGLUTWindow
= OSG::GLUTWindow::create();
221 if(pGLUTWindow
== NULL
)
224 glutInitDisplayMode(uiDisplayMode
);
226 if(this->getXPos() > 0.f
&& this->getYPos() > 0.f
)
228 glutInitWindowPosition(Int32(this->getXPos()),
229 Int32(this->getYPos()));
232 if(this->getXSize() > 0.f
&& this->getYSize() > 0.f
)
234 glutInitWindowSize(Int32(this->getXSize()),
235 Int32(this->getYSize()));
238 _iGlutWinId
= glutCreateWindow("OpenSG - CSM");
240 pGLUTWindow
->setGlutId(_iGlutWinId
);
242 if(this->getXSize() > 0.f
&& this->getYSize() > 0.f
)
244 pGLUTWindow
->resize(Int32(this->getXSize()),
245 Int32(this->getYSize()));
248 if(ComplexSceneManager::the() != NULL
&&
249 this->getRegisterMainLoop() == true )
251 ComplexSceneManager::the()->setMainloop(glutMainLoop
);
255 if(_pVSCWindow
->getXSize () < 0.f
&&
256 _pVSCWindow
->getYSize () < 0.f
&&
257 _pVSCWindow
->getDecorEnabled() == false)
262 // _bSceneWireframe = _pVSCWindow->getSFSceneWireframeR()->getValue();
264 // setFCPtr(pGLUTWindow);
266 _pWindow
= pGLUTWindow
;
269 if(_bGLUTInitialized
== false)
271 _bGLUTInitialized
= true;
273 // _pFirstWindow = this;
275 glutKeyboardFunc (csmGlutKeyHandler
);
276 // glutVisibilityFunc(vscGlutVisHandler );
277 glutReshapeFunc (csmGlutReshapeHandler
);
278 glutDisplayFunc (csmGlutFrameHandler
);
279 glutMouseFunc (csmGlutMouseHandler
);
280 glutMotionFunc (csmGlutMouseMotionHandler
);
281 glutIdleFunc (csmGlutFrameHandler
);
287 OSG::IndentFileOutStream
outFileStream("/tmp/window.osg");
291 std::cerr
<< "STARTING PRINTOUT:" << std::endl
;
293 OSG::OSGWriter
writer(outFileStream
, 4);
295 writer
.write(_pOSGWindow
);
297 outFileStream
.close();
303 // pGLUTWindow->deactivate();