fixed: gcc8 compile issues
[opensg.git] / Source / Contrib / ComplexSceneManager / GLUT / OSGCSMGLUTWindow.cpp
blob468cb8fa7ac8292f3656e71b6a8ffea7f5031c3c
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2006 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
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. *
18 * *
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. *
23 * *
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. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 //---------------------------------------------------------------------------
40 // Includes
41 //---------------------------------------------------------------------------
43 #include <cstdlib>
44 #include <cstdio>
46 #include "OSGConfig.h"
48 #include "OSGCSMGLUTWindow.h"
49 #include "OSGGLUT.h"
50 #include "OSGGLUTWindow.h"
51 #include "OSGComplexSceneManager.h"
53 OSG_BEGIN_NAMESPACE
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 /***************************************************************************\
61 * Class variables *
62 \***************************************************************************/
64 bool CSMGLUTWindow::_bGLUTInitialized = false;
65 CSMGLUTWindow *CSMGLUTWindow::_pGLUTWindow = NULL;
67 /***************************************************************************\
68 * Class methods *
69 \***************************************************************************/
71 void CSMGLUTWindow::initMethod(InitPhase ePhase)
73 Inherited::initMethod(ePhase);
75 if(ePhase == TypeObject::SystemPost)
80 void CSMGLUTWindow::csmGlutKeyHandler(UChar8 key,
81 Int32 x,
82 Int32 y )
84 switch(key)
86 case 27:
88 glutKeyboardFunc (NULL);
89 glutReshapeFunc (NULL);
90 // glutDisplayFunc (NULL);
91 glutMouseFunc (NULL);
92 glutMotionFunc (NULL);
93 glutIdleFunc (NULL);
95 ComplexSceneManager::the()->terminate();
97 osgExit();
99 exit(0);
101 break;
103 default:
104 ComplexSceneManager::the()->key(x,
106 CSMKeyData::ButtonDown,
107 key);
108 break;
112 void CSMGLUTWindow::csmGlutReshapeHandler(Int32 w,
113 Int32 h)
115 _pGLUTWindow->reshape(w, h);
117 glutPostRedisplay();
120 void CSMGLUTWindow::csmGlutFrameHandler(void)
122 ComplexSceneManager::the()->frame();
124 Thread::getCurrentChangeList()->commitChangesAndClear();
127 void CSMGLUTWindow::csmGlutMouseHandler(Int32 iButton,
128 Int32 iState,
129 Int32 x,
130 Int32 y )
132 _pGLUTWindow->mouse(iButton,
133 iState,
134 1 | (glutGetModifiers() << 1),
139 void CSMGLUTWindow::csmGlutMouseMotionHandler(Int32 x,
140 Int32 y)
142 _pGLUTWindow->motion(x, y, 1 | (glutGetModifiers() << 1));
145 /***************************************************************************\
146 * Instance methods *
147 \***************************************************************************/
149 /*-------------------------------------------------------------------------*\
150 - private -
151 \*-------------------------------------------------------------------------*/
153 /*----------------------- constructors & destructors ----------------------*/
155 CSMGLUTWindow::CSMGLUTWindow(void) :
156 Inherited ( ),
157 _iGlutWinId(-1)
161 CSMGLUTWindow::CSMGLUTWindow(const CSMGLUTWindow &source) :
162 Inherited (source),
163 _iGlutWinId(-1 )
167 CSMGLUTWindow::~CSMGLUTWindow(void)
171 void CSMGLUTWindow::terminateGLContext(void)
173 if(_pWindow != NULL)
175 _pWindow->terminate();
178 glutDestroyWindow(_iGlutWinId);
181 /*----------------------------- class specific ----------------------------*/
183 void CSMGLUTWindow::changed(ConstFieldMaskArg whichField,
184 UInt32 origin,
185 BitVector details)
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)
200 Int32 argc = 1;
201 const Char8 *argv[] = { "testCSM" };
203 glutInit(&argc, const_cast<Char8 **>(argv));
206 UInt32 uiDisplayMode = (GLUT_RGBA |
207 GLUT_DEPTH |
208 GLUT_DOUBLE |
209 GLUT_STENCIL |
210 GLUT_MULTISAMPLE);
212 #if 0
213 if(_pVSCWindow->stereo() == true)
215 uiDisplayMode |= GLUT_STEREO;
217 #endif
219 OSG::GLUTWindowUnrecPtr pGLUTWindow = OSG::GLUTWindow::create();
221 if(pGLUTWindow == NULL)
222 return false;
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);
254 #if 0
255 if(_pVSCWindow->getXSize () < 0.f &&
256 _pVSCWindow->getYSize () < 0.f &&
257 _pVSCWindow->getDecorEnabled() == false)
259 glutFullScreen();
261 #endif
262 // _bSceneWireframe = _pVSCWindow->getSFSceneWireframeR()->getValue();
264 // setFCPtr(pGLUTWindow);
266 _pWindow = pGLUTWindow;
267 _pGLUTWindow = this;
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 );
284 pGLUTWindow->init();
286 #if 0
287 OSG::IndentFileOutStream outFileStream("/tmp/window.osg");
289 if(outFileStream)
291 std::cerr << "STARTING PRINTOUT:" << std::endl;
293 OSG::OSGWriter writer(outFileStream, 4);
295 writer.write(_pOSGWindow);
297 outFileStream.close();
299 #endif
301 Inherited::init();
303 // pGLUTWindow->deactivate();
305 return true;
308 OSG_END_NAMESPACE