00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include <stdlib.h>
00044 #include <stdio.h>
00045
00046 #include "OSGConfig.h"
00047
00048 #include <OSGGL.h>
00049
00050 #include <OSGFieldContainer.h>
00051 #include <OSGNode.h>
00052 #include <OSGAction.h>
00053 #include <OSGDrawAction.h>
00054 #include "OSGViewport.h"
00055 #include "OSGCamera.h"
00056 #include "OSGWindow.h"
00057 #include "OSGBackground.h"
00058 #include "OSGGradientBackground.h"
00059 #include "OSGTileCameraDecorator.h"
00060
00061 OSG_USING_NAMESPACE
00062
00063
00064
00065
00066
00067
00080
00081
00082
00083
00084 const OSG::BitVector GradientBackground::LineFieldMask =
00085 (GradientBackground::PositionFieldMask |
00086 GradientBackground::ColorFieldMask );
00087
00088
00089
00090
00091
00092 void GradientBackground::initMethod (void)
00093 {
00094 }
00095
00096
00097
00098
00099
00100
00101
00102 GradientBackground::GradientBackground(void) :
00103 Inherited()
00104 {
00105 }
00106
00107 GradientBackground::GradientBackground(const GradientBackground &source) :
00108 Inherited(source)
00109 {
00110 }
00111
00112 GradientBackground::~GradientBackground(void)
00113 {
00114 }
00115
00116 void GradientBackground::changed(BitVector whichField, UInt32 origin)
00117 {
00118 Inherited::changed(whichField, origin);
00119 }
00120
00121
00122
00123 void GradientBackground::clear(DrawActionBase *act, Viewport *port)
00124 {
00125 Int32 bit = getClearStencilBit();
00126
00127 if(_mfPosition.size() < 2)
00128 {
00129 Real32 r = 0, g = 0, b = 0;
00130
00131 if(_mfPosition.size() == 1)
00132 {
00133 Color3f col = _mfColor[0];
00134 col.getValuesRGB(r, g, b);
00135 }
00136
00137 glClearColor(r, g, b, 1);
00138
00139 if (bit >= 0)
00140 {
00141 glClearStencil(bit);
00142 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
00143 }
00144 else
00145 {
00146 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00147 }
00148 }
00149 else
00150 {
00151 glPushAttrib(GL_POLYGON_BIT | GL_DEPTH_BUFFER_BIT |
00152 GL_LIGHTING_BIT);
00153
00154 glDisable(GL_LIGHTING);
00155 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
00156 glDisable(GL_DEPTH_TEST);
00157 glDisable(GL_COLOR_MATERIAL);
00158
00159 glMatrixMode(GL_MODELVIEW);
00160 glPushMatrix();
00161 glLoadIdentity();
00162
00163 glMatrixMode(GL_PROJECTION);
00164 glPushMatrix();
00165 glLoadIdentity();
00166
00167 UInt32 width = port->getPixelWidth(),
00168 height = port->getPixelHeight();
00169
00170 Camera *cP = act->getCamera();
00171 TileCameraDecorator *cdP = dynamic_cast<TileCameraDecorator*>(cP);
00172
00173 while (cdP != NULL)
00174 {
00175 width = cdP->getFullWidth() ? cdP->getFullWidth() : width;
00176 height = cdP->getFullHeight() ? cdP->getFullHeight() : height;
00177
00178 cP = cdP->getDecoratee().getCPtr();
00179 cdP = dynamic_cast<TileCameraDecorator*>(cP);
00180 }
00181
00182 cP = act->getCamera();
00183 cdP = dynamic_cast<TileCameraDecorator*>(cP);
00184
00185 if (cdP)
00186 {
00187 Real32 left = cdP->getLeft(),
00188 right = cdP->getRight(),
00189 top = cdP->getTop(),
00190 bottom = cdP->getBottom();
00191
00192 glOrtho( left , right, bottom, top, 0, 1);
00193 }
00194 else
00195 {
00196 glOrtho(0, 1, 0, 1, 0, 1);
00197 }
00198
00199 Real32 r1, g1, b1;
00200 UInt32 size = _mfPosition.size();
00201
00202 glBegin(GL_QUAD_STRIP);
00203
00204 Real32 pos = _mfPosition[0];
00205 if(pos > 0)
00206 {
00207 glColor3f(0.0, 0.0, 0.0);
00208 glVertex3f(0, 0, 0);
00209 glVertex3f(1, 0, 0);
00210 }
00211
00212 for(UInt32 i = 0; i < size; i++)
00213 {
00214 pos = _mfPosition[i];
00215
00216 Color3f col1 = _mfColor[i];
00217 col1.getValuesRGB(r1, g1, b1);
00218
00219 glColor3f(r1, g1, b1);
00220 glVertex3f(0, pos, 0);
00221 glVertex3f(1, pos, 0);
00222 }
00223
00224 if(pos < 1)
00225 {
00226 glColor3f(0.0, 0.0, 0.0);
00227 glVertex3f(0, 1, 0);
00228 glVertex3f(1, 1, 0);
00229 }
00230
00231 glEnd();
00232
00233 glPopMatrix();
00234 glMatrixMode(GL_MODELVIEW);
00235 glPopMatrix();
00236
00237 glPopAttrib();
00238
00239 if (bit >= 0)
00240 {
00241 glClearStencil(bit);
00242 glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
00243 }
00244 else
00245 {
00246 glClear(GL_DEPTH_BUFFER_BIT);
00247 }
00248 }
00249 }
00250
00251
00252
00253 void GradientBackground::dump( UInt32 OSG_CHECK_ARG(uiIndent),
00254 const BitVector OSG_CHECK_ARG(bvFlags)) const
00255 {
00256 SLOG << "Dump GradientBackground NI" << std::endl;
00257 }
00258
00259
00260
00261
00262
00263
00264 #ifdef OSG_SGI_CC
00265 #pragma set woff 1174
00266 #endif
00267
00268 #ifdef OSG_LINUX_ICC
00269 #pragma warning( disable : 177 )
00270 #endif
00271
00272 namespace
00273 {
00274 static Char8 cvsid_cpp [] = "@(#)$Id: FCTemplate_cpp.h,v 1.13 2002/06/01 10:37:25 vossg Exp $";
00275 static Char8 cvsid_hpp [] = OSGGRADIENTBACKGROUND_HEADER_CVSID;
00276 static Char8 cvsid_inl [] = OSGGRADIENTBACKGROUND_INLINE_CVSID;
00277
00278 static Char8 cvsid_fields_hpp[] = OSGGRADIENTBACKGROUNDFIELDS_HEADER_CVSID;
00279 }
00280
00281 #ifdef __sgi
00282 #pragma reset woff 1174
00283 #endif
00284
00285