1 /*---------------------------------------------------------------------------*\
5 * Copyright(C) 2000-2005 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"
50 #include "OSGFieldContainer.h"
52 #include "OSGAction.h"
53 #include "OSGViewport.h"
54 #include "OSGCamera.h"
55 #include "OSGWindow.h"
58 #include "OSGImageForeground.h"
62 // Documentation for this class is emited in the
63 // OSGImageForegroundBase.cpp file.
64 // To modify it, please change the .fcd file (OSGImageForeground.fcd) and
65 // regenerate the base file.
67 /***************************************************************************\
69 \***************************************************************************/
71 /*-------------------------------------------------------------------------*\
73 \*-------------------------------------------------------------------------*/
75 void ImageForeground::initMethod(InitPhase ePhase
)
77 Inherited::initMethod(ePhase
);
80 /***************************************************************************\
82 \***************************************************************************/
84 /*------------- constructors & destructors --------------------------------*/
86 ImageForeground::ImageForeground(void) :
91 ImageForeground::ImageForeground(const ImageForeground
&source
) :
96 ImageForeground::~ImageForeground(void)
100 void ImageForeground::changed(ConstFieldMaskArg whichField
,
104 Inherited::changed(whichField
, origin
, details
);
107 /*------------------------------- dump ----------------------------------*/
109 void ImageForeground::dump( UInt32
OSG_CHECK_ARG(uiIndent
),
110 const BitVector
OSG_CHECK_ARG(bvFlags
)) const
112 SLOG
<< "Dump ImageForeground NI" << std::endl
;
116 void ImageForeground::draw(DrawEnv
* pEnv
)
118 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
119 if(getActive() == false)
124 for(i
= 0; i
< getMFPositions()->size(); i
++)
126 if(getImages(i
) != NULL
)
130 if(i
== getMFPositions()->size()) // all images == NULL?
133 glPushAttrib(GL_POLYGON_BIT
| GL_DEPTH_BUFFER_BIT
|
136 glPolygonMode(GL_FRONT_AND_BACK
, GL_FILL
);
138 glDisable(GL_DEPTH_TEST
);
140 glDisable(GL_COLOR_MATERIAL
);
142 glDisable(GL_TEXTURE_2D
);
144 glMatrixMode(GL_MODELVIEW
);
148 glMatrixMode(GL_PROJECTION
);
151 glOrtho(0, 1, 0, 1, 0, 1);
153 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
156 float vpWidth
= 1.0, vpHeight
= 1.0;
158 // for absolute pixel position
159 vpWidth
= 1.0 / pEnv
->getPixelWidth ();
160 vpHeight
= 1.0 / pEnv
->getPixelHeight();
162 for(i
= 0; i
< getMFPositions()->size(); i
++)
164 Image
*img
= getImages(i
);
169 Pnt2f p
= getPositions(i
);
171 if(p
[0] >= 1.0 || p
[1] >= 1.0)
173 glRasterPos2f(p
[0] * vpWidth
, p
[1] * vpHeight
); // absolute
178 glRasterPos2f(p
[0], p
[1]); // relative position
181 if(i
< this->getMFScales()->size())
183 glPixelZoom(this->getScales(i
)[0],
184 this->getScales(i
)[1]);
187 glDrawPixels(img
->getWidth(),
189 img
->getPixelFormat(),
193 glPixelZoom(1.f
, 1.f
);
199 glMatrixMode(GL_MODELVIEW
);
206 void ImageForeground::subImage(Image
*image
)
208 MFImagesType::const_iterator imgIt
= getMFImages()->find(image
);
210 if(imgIt
!= getMFImages()->end())
212 MFImagesType::difference_type iIdx
=
213 std::distance(getMFImages()->begin(), imgIt
);
215 editMFImages ()->erase(iIdx
);
216 editMFPositions()->erase(iIdx
);