Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

OSGXWindow.cpp

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *             Copyright (C) 2000-2002 by the OpenSG Forum                   *
00006  *                                                                           *
00007  *                            www.opensg.org                                 *
00008  *                                                                           *
00009  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
00010  *                                                                           *
00011 \*---------------------------------------------------------------------------*/
00012 /*---------------------------------------------------------------------------*\
00013  *                                License                                    *
00014  *                                                                           *
00015  * This library is free software; you can redistribute it and/or modify it   *
00016  * under the terms of the GNU Library General Public License as published    *
00017  * by the Free Software Foundation, version 2.                               *
00018  *                                                                           *
00019  * This library is distributed in the hope that it will be useful, but       *
00020  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00022  * Library General Public License for more details.                          *
00023  *                                                                           *
00024  * You should have received a copy of the GNU Library General Public         *
00025  * License along with this library; if not, write to the Free Software       *
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00027  *                                                                           *
00028 \*---------------------------------------------------------------------------*/
00029 /*---------------------------------------------------------------------------*\
00030  *                                Changes                                    *
00031  *                                                                           *
00032  *                                                                           *
00033  *                                                                           *
00034  *                                                                           *
00035  *                                                                           *
00036  *                                                                           *
00037 \*---------------------------------------------------------------------------*/
00038 
00039 //---------------------------------------------------------------------------
00040 //  Includes
00041 //---------------------------------------------------------------------------
00042 
00043 #include <stdlib.h>
00044 #include <stdio.h>
00045 
00046 #include <OSGConfig.h>
00047 
00048 #define OSG_COMPILEWINDOWXINST
00049 
00050 #include "OSGXWindow.h"
00051 
00052 OSG_USING_NAMESPACE
00053 
00060 /*----------------------- constructors & destructors ----------------------*/
00061 
00063 
00064 XWindow::XWindow(void) :
00065     Inherited()
00066 {
00067 }
00068 
00070 
00071 XWindow::XWindow(const XWindow &source) :
00072     Inherited(source)
00073 {
00074 }
00075 
00077 
00078 XWindow::~XWindow(void)
00079 {
00080 }
00081 
00082 /*----------------------------- class specific ----------------------------*/
00083 
00085 
00086 void XWindow::initMethod (void)
00087 {
00088 }
00089 
00091 
00092 void XWindow::changed(BitVector whichField, UInt32 origin)
00093 {
00094     Inherited::changed(whichField, origin);
00095 }
00096 
00098 
00099 void XWindow::dump(      UInt32    , 
00100                          const BitVector ) const
00101 {
00102     SLOG << "Dump XWindow NI" << std::endl;
00103 }
00104 
00105 
00106 
00109 void XWindow::init(void)
00110 {    
00111     XVisualInfo       *vi, visInfo;
00112     XWindowAttributes winAttr;
00113 
00114     XGetWindowAttributes(getDisplay(), getWindow(), &winAttr);
00115 
00116     // get the existing glWidget's visual-id
00117     memset(&visInfo, 0, sizeof(XVisualInfo));
00118     visInfo.visualid = XVisualIDFromVisual(winAttr.visual);
00119 
00120     // get new display-variable
00121     if(getDisplay() == NULL)
00122     {
00123         setDisplay(XOpenDisplay(DisplayString(getDisplay())));  
00124     }
00125 
00126     // get a visual for the glx context
00127     int nvis;
00128     vi = XGetVisualInfo(getDisplay(), VisualIDMask, &visInfo, &nvis);
00129 
00130     // is the visual GL-capable ?
00131     int useGL;
00132     glXGetConfig(getDisplay(), 
00133                  vi, 
00134                  GLX_USE_GL, 
00135                  &useGL );
00136     if (!useGL)
00137     {
00138         SFATAL << "Visual is not OpenGL-capable!" << std::endl;
00139     }    
00140   
00141     XWindowPtr win(*this);
00142     beginEditCP(win, ContextFieldMask);
00143     // create the new context
00144     setContext(glXCreateContext(getDisplay(), vi, None, GL_TRUE));
00145     endEditCP  (win, ContextFieldMask);
00146 
00147     glXMakeCurrent(getDisplay(), getWindow(), getContext());
00148     setupGL();
00149 }
00150     
00151 // activate the window: bind the OGL context    
00152 void XWindow::activate( void )
00153 {
00154     glXMakeCurrent(getDisplay(), getWindow(), getContext());
00155 }
00156     
00157 // activate the window: bind the OGL context    
00158 void XWindow::deactivate( void )
00159 {
00160     glXMakeCurrent(getDisplay(), None, NULL);
00161 }
00162     
00163 // swap front and back buffers  
00164 void XWindow::swap( void )
00165 {
00166     glXSwapBuffers(getDisplay(), getWindow());
00167 }
00168 
00169 #include <OSGMFieldTypeDef.inl>
00170 #include <OSGSFieldTypeDef.inl>
00171 
00172 OSG_BEGIN_NAMESPACE
00173 
00174 // doxygen can't find these
00175 #ifndef OSG_DO_DOC 
00176 
00177 DataType FieldDataTraits<DisplayP>   ::_type("DisplayP", NULL);
00178 DataType FieldDataTraits<X11Window>  ::_type("X11Window", NULL);
00179 DataType FieldDataTraits1<GLXContext>::_type("GLXContext", NULL);
00180 
00181 #endif
00182 
00183 OSG_DLLEXPORT_SFIELD_DEF1(DisplayP,      OSG_WINDOWXLIB_DLLTMPLMAPPING);
00184 OSG_DLLEXPORT_MFIELD_DEF1(DisplayP,      OSG_WINDOWXLIB_DLLTMPLMAPPING);
00185 OSG_DLLEXPORT_SFIELD_DEF1(X11Window,     OSG_WINDOWXLIB_DLLTMPLMAPPING);
00186 OSG_DLLEXPORT_MFIELD_DEF1(X11Window,     OSG_WINDOWXLIB_DLLTMPLMAPPING);
00187 OSG_DLLEXPORT_SFIELD_DEF2(GLXContext, 1, OSG_WINDOWXLIB_DLLTMPLMAPPING);
00188 OSG_DLLEXPORT_MFIELD_DEF2(GLXContext, 1, OSG_WINDOWXLIB_DLLTMPLMAPPING);
00189 
00190 OSG_END_NAMESPACE
00191 
00192 /*-------------------------------------------------------------------------*/
00193 /*                              cvs id's                                   */
00194 
00195 #ifdef __sgi
00196 #pragma set woff 1174
00197 #endif
00198 
00199 #ifdef OSG_LINUX_ICC
00200 #pragma warning( disable : 177 )
00201 #endif
00202 
00203 namespace
00204 {
00205     static char cvsid_cpp[] = "@(#)$Id: $";
00206     static char cvsid_hpp[] = OSGXWINDOW_HEADER_CVSID;
00207     static char cvsid_inl[] = OSGXWINDOW_INLINE_CVSID;
00208 
00209     static char cvsid_fields_hpp[] = OSGWINDOWXFIELDS_HEADER_CVSID;
00210 }
00211 

Generated on Thu Aug 25 04:12:16 2005 for OpenSG by  doxygen 1.4.3