1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2002 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 // Forget everything if we're not doing a windows compile
51 #include "OSGWIN32Window.h"
55 // Documentation for this class is emited in the
56 // OSGWIN32WindowBase.cpp file.
57 // To modify it, please change the .fcd file (OSGWIN32Window.fcd) and
58 // regenerate the base file.
60 /*----------------------- constructors & destructors ----------------------*/
64 WIN32Window::WIN32Window(void) :
71 WIN32Window::WIN32Window(const WIN32Window
&source
) :
78 WIN32Window::~WIN32Window(void)
82 /*----------------------------- class specific ----------------------------*/
84 //! initialize the static features of the class, e.g. action callbacks
86 void WIN32Window::initMethod(InitPhase ePhase
)
88 Inherited::initMethod(ePhase
);
91 //! react to field changes
93 void WIN32Window::changed(BitVector whichField
,
97 Inherited::changed(whichField
, origin
, details
);
100 //! output the instance for debug purposes
102 void WIN32Window::dump( UInt32
,
103 const BitVector
) const
105 SLOG
<< "Dump WIN32Window NI" << std::endl
;
108 /*-------------------------- your_category---------------------------------*/
110 /*! init the window: create the HDC and HGLRC
112 void WIN32Window::init(GLInitFunctor oFunc
)
114 setHdc(GetDC(getHwnd()));
116 if(getHglrc() == NULL
)
118 setHglrc(wglCreateContext(getHdc()));
120 if(getHglrc() == NULL
)
122 std::cerr
<< "WIN32Window::init: failed: "
128 Inherited::init(oFunc
);
132 ReleaseDC(getHwnd(), getHdc());
138 void WIN32Window::terminate(void)
140 Inherited::doTerminate();
142 if(getHglrc() != NULL
)
144 this->doDeactivate();
146 wglDeleteContext(getHglrc());
153 /*! activate the window: set the HDC and bind the OGL context
155 void WIN32Window::doActivate( void )
158 setHdc(GetDC(getHwnd()));
160 if(!wglMakeCurrent(getHdc(), getHglrc()))
162 std::cerr
<< "WIN32Window::activate: failed: "
168 void WIN32Window::doDeactivate ( void )
170 // unbind the context
171 wglMakeCurrent(NULL
, NULL
);
173 // release the hardware device context
176 ReleaseDC(getHwnd(), getHdc());
181 // swap front and back buffers
182 bool WIN32Window::doSwap(void)
185 setHdc(GetDC(getHwnd()));
187 return SwapBuffers(getHdc()) != 0;
190 bool WIN32Window::hasContext(void)
192 return (this->getHglrc() != NULL
);