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"
47 #include "OSGMaterial.h"
48 #include "OSGViewport.h"
50 #include "OSGPolygonBackground.h"
51 #include "OSGTileCameraDecorator.h"
52 #include "OSGDrawEnv.h"
53 #include "OSGRenderActionBase.h"
54 #include "OSGPrimeMaterial.h"
58 // Documentation for this class is emited in the
59 // OSGPolygonBackgroundBase.cpp file.
60 // To modify it, please change the .fcd file (OSGPolygonBackground.fcd) and
61 // regenerate the base file.
63 /***************************************************************************\
65 \***************************************************************************/
67 /***************************************************************************\
69 \***************************************************************************/
71 void PolygonBackground::initMethod(InitPhase ePhase
)
73 Inherited::initMethod(ePhase
);
77 /***************************************************************************\
79 \***************************************************************************/
81 /*-------------------------------------------------------------------------*\
83 \*-------------------------------------------------------------------------*/
85 /*----------------------- constructors & destructors ----------------------*/
87 PolygonBackground::PolygonBackground(void) :
92 PolygonBackground::PolygonBackground(const PolygonBackground
&source
) :
97 PolygonBackground::~PolygonBackground(void)
101 /*----------------------------- class specific ----------------------------*/
103 void PolygonBackground::clear(DrawEnv
*pEnv
)
105 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
106 if(pEnv
->getPixelWidth() == 0 ||
107 pEnv
->getPixelHeight() == 0 )
109 FWARNING(("Port has zero size: nothing to render to!\n"));
113 if(getMFPositions()->size() == 0 ||
114 getMFPositions()->size() != getMFTexCoords()->size())
116 FWARNING(("PolygonBackground::clear: positions and texcoords have "
117 "different/ invalid sizes (%" PRISize
" vs. %" PRISize
")!\n",
118 getMFPositions()->size(), getMFTexCoords()->size()));
122 Int32 bit
= getClearStencilBit(); // 0x0
128 glClear(GL_COLOR_BUFFER_BIT
|
129 GL_DEPTH_BUFFER_BIT
|
130 GL_STENCIL_BUFFER_BIT
);
134 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
137 glPushAttrib(GL_ALL_ATTRIB_BITS
);
139 glDisable(GL_DEPTH_TEST
);
140 glDepthFunc(GL_ALWAYS
);
143 glDepthMask(GL_FALSE
);
145 Real32 aspectX
= 1.0f
, aspectY
= 1.0f
;
147 if(getAspectHeight() != 0 && getAspectWidth() != 0)
149 aspectX
= (Real32(pEnv
->getPixelHeight()) / getAspectHeight()) /
150 (Real32(pEnv
->getPixelWidth ()) / getAspectWidth ());
153 Real32 sFac
= getScale() > 0 ? getScale() : 1.0f
;
159 beginOrthoRender(pEnv
, getNormalizedX(), getNormalizedY(),
160 fullWidth
, fullHeight
);
164 if(getAspectHeight() != 0 && getAspectWidth() != 0 &&
165 fullHeight
!= 0 && fullHeight
!= 0 )
167 aspectX
= (Real32(fullHeight
) / getAspectHeight()) /
168 (Real32(fullWidth
) / getAspectWidth ());
170 t
= Real32(fullWidth
) * (1.0f
- aspectX
) * 0.5f
;
171 t
*= Real32(pEnv
->getPixelWidth()) / fullWidth
;
174 glTranslatef(t
, 0.0f
, 0.0f
);
175 glScalef (aspectX
, aspectY
, 1.0f
);
177 Real32 tW
= (1.0f
- sFac
) * 0.5f
* Real32(pEnv
->getPixelWidth ());
178 Real32 tH
= (1.0f
- sFac
) * 0.5f
* Real32(pEnv
->getPixelHeight());
180 glTranslatef(tW
, tH
, 0.0f
);
181 glScalef (sFac
, sFac
, 1.0f
);
185 glScalef(sFac
, sFac
, 1.0f
);
186 glScalef(aspectX
, aspectY
, 1.0f
);
188 beginOrthoRender(pEnv
, getNormalizedX(), getNormalizedY(),
189 fullWidth
, fullHeight
);
193 getMaterial()->getState()->activate(pEnv
);
195 const Vec3f
*tc
= &getMFTexCoords()->front();
196 const Pnt2f
*pos
= &getMFPositions()->front();
200 for (UInt16 i
=0; i
< getMFPositions()->size(); i
++)
202 glTexCoord3fv( tc
[i
].getValues());
203 glVertex2fv (pos
[i
].getValues());
208 getMaterial()->getState()->deactivate(pEnv
);
216 glClear(GL_DEPTH_BUFFER_BIT
| GL_STENCIL_BUFFER_BIT
);
220 glClear(GL_DEPTH_BUFFER_BIT
);
224 endOrthoRender(pEnv
);
230 void PolygonBackground::changed(ConstFieldMaskArg whichField
,
234 Inherited::changed(whichField
, origin
, details
);
237 void PolygonBackground::dump( UInt32
,
238 const BitVector
) const
240 SLOG
<< "Dump PolygonBackground NI" << std::endl
;