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; ifnot, 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"
56 #include "OSGBackground.h"
57 #include "OSGGradientBackground.h"
58 #include "OSGTileCameraDecorator.h"
59 #include "OSGDrawEnv.h"
63 // Documentation for this class is emited in the
64 // OSGGradientBackgroundBase.cpp file.
65 // To modify it, please change the .fcd file (OSGGradientBackground.fcd) and
66 // regenerate the base file.
68 /***************************************************************************\
70 \***************************************************************************/
72 const OSG::BitVector
GradientBackground::LineFieldMask
=
73 (GradientBackground::PositionFieldMask
|
74 GradientBackground::ColorFieldMask
);
76 /***************************************************************************\
78 \***************************************************************************/
80 void GradientBackground::initMethod(InitPhase ePhase
)
82 Inherited::initMethod(ePhase
);
85 /***************************************************************************\
87 \***************************************************************************/
89 /*------------- constructors & destructors --------------------------------*/
91 GradientBackground::GradientBackground(void) :
96 GradientBackground::GradientBackground(const GradientBackground
&source
) :
101 GradientBackground::~GradientBackground(void)
105 void GradientBackground::changed(ConstFieldMaskArg whichField
,
109 Inherited::changed(whichField
, origin
, details
);
112 /*-------------------------- your_category---------------------------------*/
114 void GradientBackground::clear(DrawEnv
*pEnv
)
116 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
117 Int32 stencilBit
= getClearStencilBit(); // 0x0
118 GLbitfield clearMask
= 0;
120 if(getClearColor() == true)
122 if(_mfPosition
.size() < 2)
124 // too few positions for a real gradient - just clear the buffer
126 clearMask
|= GL_COLOR_BUFFER_BIT
;
128 if(_mfPosition
.size() == 1)
130 const Color3f
&col
= _mfColor
[0];
132 glClearColor(col
[0], col
[1], col
[2], 1.0);
137 // draw gradient - don't need to clear the color buffer
139 glPushAttrib(GL_POLYGON_BIT
| GL_DEPTH_BUFFER_BIT
|
142 glDisable(GL_LIGHTING
);
143 glPolygonMode(GL_FRONT_AND_BACK
, GL_FILL
);
144 glDisable(GL_DEPTH_TEST
);
145 glDisable(GL_COLOR_MATERIAL
);
150 // setup ortho projection
151 beginOrthoRender(pEnv
, getNormPosition(), getNormPosition(),
152 fullWidth
, fullHeight
);
154 glBegin(GL_QUAD_STRIP
);
156 UInt32 size
= _mfPosition
.size32();
157 Real32 pos
= _mfPosition
[0];
158 UInt32 style
= getStyle();
166 glColor3f(0.0, 0.0, 0.0);
167 glVertex2f(0.0f
, 0.0f
);
168 glVertex2f(fullWidth
, 0.0f
);
171 for(UInt32 i
= 0; i
< size
; ++i
)
173 pos
= _mfPosition
[i
];
174 const Color3f
&col
= _mfColor
[i
];
176 glColor3f(col
[0], col
[1], col
[2]);
177 glVertex2f(0.0f
, pos
);
178 glVertex2f(fullWidth
, pos
);
183 glColor3f(0.0, 0.0, 0.0);
184 glVertex2f(0.0f
, fullHeight
);
185 glVertex2f(fullWidth
, fullHeight
);
195 glColor3f(0.0, 0.0, 0.0);
196 glVertex2f(0.0f
, 0.0f
);
197 glVertex2f(0.0f
, fullHeight
);
200 for(UInt32 i
= 0; i
< size
; i
++)
202 pos
= _mfPosition
[i
];
203 const Color3f
&col
= _mfColor
[i
];
205 glColor3f(col
[0], col
[1], col
[2]);
206 glVertex2f(pos
, 0.0f
);
207 glVertex2f(pos
, fullHeight
);
212 glColor3f(0.0, 0.0, 0.0);
213 glVertex2f(fullWidth
, 0.0f
);
214 glVertex2f(fullWidth
, fullHeight
);
222 FWARNING(("GradientBackground: "
223 "SFStyle has invalid value [%u].\n", style
));
230 endOrthoRender(pEnv
);
236 if(getClearDepth() == true)
238 clearMask
|= GL_DEPTH_BUFFER_BIT
;
240 glClearDepth(getDepth());
245 clearMask
|= GL_STENCIL_BUFFER_BIT
;
247 glClearStencil(stencilBit
);
257 /*------------------------------- dump ----------------------------------*/
259 void GradientBackground::dump( UInt32
OSG_CHECK_ARG(uiIndent
),
260 const BitVector
OSG_CHECK_ARG(bvFlags
)) const
262 SLOG
<< "Dump GradientBackground NI" << std::endl
;