changed: auto add updateData callback to stages so that stagedata can be updated...
[opensg.git] / Source / WindowSystem / GLUT / OSGGLUTWindow.cpp
blobc6ac49f941a9e9ad688a1147677e61e0b57280ea
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2002 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 #if defined(OSG_WITH_GLUT) || defined(OSG_DO_DOC)
50 #define OSG_COMPILEWINDOWGLUTINST
52 #include "OSGGLUTWindow.h"
54 #include "OSGGLUT.h"
56 #include "OSGViewport.h"
57 #include "OSGCamera.h"
58 #include "OSGBackground.h"
59 #include "OSGGLUTWindow.h"
60 #include "OSGRenderActionBase.h"
61 #include "OSGRenderActionTask.h"
63 #ifdef OSG_USE_GLX
64 #include <GL/glx.h>
65 #endif
66 #ifdef __APPLE__
67 #include "OSGCocoaWindowWrapper.h"
68 #endif
70 OSG_BEGIN_NAMESPACE
72 // Documentation for this class is emited in the
73 // OSGGLUTWindowBase.cpp file.
74 // To modify it, please change the .fcd file (OSGGLUTWindow.fcd) and
75 // regenerate the base file.
77 /*----------------------- constructors & destructors ----------------------*/
79 //! Constructor
80 GLUTWindow::GLUTWindow(void) :
81 Inherited()
83 _sfDrawMode.setValue(
84 (_sfDrawMode.getValue() & ~Window::ContextMask) |
85 (Window::ExternalContext & Window::ContextMask) );
88 //! Copy Constructor
89 GLUTWindow::GLUTWindow(const GLUTWindow &source) :
90 Inherited(source)
92 _sfDrawMode.setValue(
93 (_sfDrawMode.getValue() & ~Window::ContextMask) |
94 (Window::ExternalContext & Window::ContextMask) );
97 //! Destructor
98 GLUTWindow::~GLUTWindow(void)
102 /*----------------------------- class specific ----------------------------*/
104 //! initialize the static features of the class, e.g. action callbacks
106 void GLUTWindow::initMethod(InitPhase ePhase)
108 Inherited::initMethod(ePhase);
111 //! react to field changes
112 void GLUTWindow::changed(ConstFieldMaskArg whichField,
113 UInt32 origin,
114 BitVector details)
116 Inherited::changed(whichField, origin, details);
119 //! output the instance for debug purposes
121 void GLUTWindow::dump( UInt32 ,
122 const BitVector ) const
124 SLOG << "Dump GLUTWindow NI" << std::endl;
127 /* ------------- Window functions -----------------------*/
129 // init the window: create the context
130 void GLUTWindow::init(GLInitFunctor oFunc)
132 #if defined(WIN32)
133 Inherited::setHdc (wglGetCurrentDC ());
134 Inherited::setHglrc(wglGetCurrentContext());
135 Inherited::setHwnd (WindowFromDC(Inherited::getHdc()));
136 #elif defined(__APPLE__)
137 Inherited::setContext(cocoaWrapperCurrentContext());
138 #else
139 glutSetWindow(getGlutId());
141 Inherited::setDisplay(glXGetCurrentDisplay ());
142 Inherited::setContext(glXGetCurrentContext ());
143 Inherited::setWindow (glXGetCurrentDrawable());
144 #endif
145 this->doDeactivate();
147 Window::init(oFunc);
150 void GLUTWindow::activate(void)
152 if((_sfDrawMode.getValue() & PartitionDrawMask) == SequentialPartitionDraw)
154 if(glutGetWindow() != getGlutId())
155 glutSetWindow(getGlutId());
157 Inherited::doActivate();
161 void GLUTWindow::terminate(void)
163 Window::doTerminate();
165 Inherited::setContext(NULL);
168 OSG_END_NAMESPACE
170 #endif // OSG_WITH_GLUT