fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / Window / Background / OSGGradientBackground.cpp
blobc740b16fe718134cd5f777f175847aa7862ec8b4
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
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. *
18 * *
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. *
23 * *
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. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 //---------------------------------------------------------------------------
40 // Includes
41 //---------------------------------------------------------------------------
43 #include <cstdlib>
44 #include <cstdio>
46 #include "OSGConfig.h"
48 #include "OSGGL.h"
50 #include "OSGFieldContainer.h"
51 #include "OSGNode.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"
61 OSG_USING_NAMESPACE
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 /***************************************************************************\
69 * Class variables *
70 \***************************************************************************/
72 const OSG::BitVector GradientBackground::LineFieldMask =
73 (GradientBackground::PositionFieldMask |
74 GradientBackground::ColorFieldMask );
76 /***************************************************************************\
77 * Class methods *
78 \***************************************************************************/
80 void GradientBackground::initMethod(InitPhase ePhase)
82 Inherited::initMethod(ePhase);
85 /***************************************************************************\
86 * Instance methods *
87 \***************************************************************************/
89 /*------------- constructors & destructors --------------------------------*/
91 GradientBackground::GradientBackground(void) :
92 Inherited()
96 GradientBackground::GradientBackground(const GradientBackground &source) :
97 Inherited(source)
101 GradientBackground::~GradientBackground(void)
105 void GradientBackground::changed(ConstFieldMaskArg whichField,
106 UInt32 origin,
107 BitVector details)
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);
135 else
137 // draw gradient - don't need to clear the color buffer
139 glPushAttrib(GL_POLYGON_BIT | GL_DEPTH_BUFFER_BIT |
140 GL_LIGHTING_BIT );
142 glDisable(GL_LIGHTING);
143 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
144 glDisable(GL_DEPTH_TEST);
145 glDisable(GL_COLOR_MATERIAL);
147 UInt32 fullWidth;
148 UInt32 fullHeight;
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();
160 switch(style)
162 case VERTICAL:
164 if(pos > 0)
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);
181 if(pos < 1)
183 glColor3f(0.0, 0.0, 0.0);
184 glVertex2f(0.0f, fullHeight);
185 glVertex2f(fullWidth, fullHeight);
188 break;
191 case HORIZONTAL:
193 if(pos > 0)
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);
210 if(pos < 1)
212 glColor3f(0.0, 0.0, 0.0);
213 glVertex2f(fullWidth, 0.0f );
214 glVertex2f(fullWidth, fullHeight);
217 break;
220 default:
222 FWARNING(("GradientBackground: "
223 "SFStyle has invalid value [%u].\n", style));
224 break;
228 glEnd();
230 endOrthoRender(pEnv);
232 glPopAttrib();
236 if(getClearDepth() == true)
238 clearMask |= GL_DEPTH_BUFFER_BIT;
240 glClearDepth(getDepth());
243 if(stencilBit >= 0)
245 clearMask |= GL_STENCIL_BUFFER_BIT;
247 glClearStencil(stencilBit);
250 if(clearMask != 0)
252 glClear(clearMask);
254 #endif
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;