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 #include <OSGMaterial.h>
00048 #include <OSGCamera.h>
00049 #include <OSGTileCameraDecorator.h>
00050
00051 #include "OSGPolygonBackground.h"
00052
00053 OSG_USING_NAMESPACE
00054
00055
00056
00057
00058
00063
00064
00065
00066
00067
00068
00069
00070
00071 void PolygonBackground::initMethod (void)
00072 {
00073 }
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 PolygonBackground::PolygonBackground(void) :
00087 Inherited()
00088 {
00089 }
00090
00091 PolygonBackground::PolygonBackground(const PolygonBackground &source) :
00092 Inherited(source)
00093 {
00094 }
00095
00096 PolygonBackground::~PolygonBackground(void)
00097 {
00098 }
00099
00100
00101
00102 Real32 PolygonBackground::mapCoordinate(Real32 val, Real32 max, bool norm)
00103 {
00104 if(val >= 0)
00105 {
00106 if (norm)
00107 val *= max;
00108 }
00109 else
00110 {
00111 val += 1;
00112
00113 if (norm)
00114 val *= max;
00115
00116 val = max + val;
00117 }
00118
00119 return val;
00120 }
00121
00122 void PolygonBackground::clear(DrawActionBase *act, Viewport *port)
00123 {
00124 if (port->getPixelWidth() == 0 ||
00125 port->getPixelHeight() == 0 )
00126 {
00127 FWARNING(("PolygonBackground::clear: "
00128 "Port has zero size: nothing to render to!\n"));
00129 return;
00130 }
00131
00132 if (getPositions().getSize() == 0 ||
00133 getPositions().getSize() != getTexCoords().getSize())
00134 {
00135 FWARNING(("PolygonBackground::clear: positions and texcoords have "
00136 "different/ invalid sizes (%d vs. %d)!\n",
00137 getPositions().getSize(), getTexCoords().getSize()));
00138 return;
00139 }
00140
00141 Int32 bit = getClearStencilBit();
00142
00143 if (bit >= 0)
00144 {
00145 glClearStencil(bit);
00146 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
00147 }
00148 else
00149 {
00150 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00151 }
00152
00153 glPushAttrib(GL_ALL_ATTRIB_BITS);
00154
00155 glDisable(GL_DEPTH_TEST);
00156 glDepthFunc(GL_ALWAYS);
00157
00158 if ( getCleanup() )
00159 glDepthMask(GL_FALSE);
00160
00161 Real32 aspectX = 1.0f, aspectY = 1.0f;
00162
00163 if (getAspectHeight() && getAspectWidth())
00164 {
00165 aspectX = ((Real32)port->getPixelHeight()/getAspectHeight()) /
00166 ((Real32)port->getPixelWidth() / getAspectWidth());
00167 }
00168
00169 glMatrixMode(GL_TEXTURE);
00170 glPushMatrix();
00171 glLoadIdentity();
00172
00173 glMatrixMode(GL_MODELVIEW);
00174 glPushMatrix();
00175 glLoadIdentity();
00176
00177 glMatrixMode(GL_PROJECTION);
00178 glPushMatrix();
00179 glLoadIdentity();
00180
00181 Real32 sFac = getScale() > 0 ? getScale() : 1.0f;
00182
00183 UInt32 width = port->getPixelWidth(),
00184 height = port->getPixelHeight();
00185
00186 Camera *cP = act->getCamera();
00187 TileCameraDecorator *cdP = dynamic_cast<TileCameraDecorator*>(cP);
00188
00189 while (cdP != NULL)
00190 {
00191 width = cdP->getFullWidth() ? cdP->getFullWidth() : width;
00192 height = cdP->getFullHeight() ? cdP->getFullHeight() : height;
00193
00194 cP = cdP->getDecoratee().getCPtr();
00195 cdP = dynamic_cast<TileCameraDecorator*>(cP);
00196 }
00197
00198 cP = act->getCamera();
00199 cdP = dynamic_cast<TileCameraDecorator*>(cP);
00200
00201 if (cdP && !getTile())
00202 {
00203 Real32 t = 0,
00204 left = cdP->getLeft(),
00205 right = cdP->getRight(),
00206 top = cdP->getTop(),
00207 bottom = cdP->getBottom();
00208
00209 if (getAspectHeight() && getAspectWidth() &&
00210 height != 0 && width != 0)
00211 {
00212 aspectX = ((Real32)height/getAspectHeight()) /
00213 ((Real32)width / getAspectWidth());
00214 t = (Real32)width * (1 - aspectX) * 0.5f;
00215 t *= (Real32)port->getPixelWidth() / width;
00216 }
00217
00218 Matrix sm;
00219 cP->getDecoration(sm, width, height);
00220
00221 glLoadMatrixf(sm.getValues());
00222 glOrtho(0, port->getPixelWidth(), 0, port->getPixelHeight(), 0, 1);
00223
00224 glTranslatef(t, 0, 0);
00225 glScalef(aspectX, aspectY, 1);
00226
00227 float t1 = (1 - sFac) * 0.5f * (Real32)port->getPixelWidth();
00228 float t2 = (1 - sFac) * 0.5f * (Real32)port->getPixelHeight();
00229 glTranslatef(t1, t2, 0);
00230 glScalef(sFac,sFac,1);
00231 }
00232 else
00233 {
00234 glScalef(sFac,sFac,1);
00235
00236 glScalef(aspectX, aspectY, 1);
00237 glOrtho(0, port->getPixelWidth(), 0, port->getPixelHeight(), 0, 1);
00238 }
00239
00240 getMaterial()->getState()->activate(act);
00241
00242 Vec3f *tc = &getTexCoords()[0];
00243 Pnt2f *pos = &getPositions()[0];
00244
00245 glBegin(GL_POLYGON);
00246
00247 for (UInt16 i=0; i<getPositions().size(); i++)
00248 {
00249 glTexCoord3fv( tc[i].getValues() );
00250 glVertex2f( mapCoordinate(pos[i][0], Real32(port->getPixelWidth()),
00251 getNormalizedX()),
00252 mapCoordinate(pos[i][1], Real32(port->getPixelHeight()),
00253 getNormalizedY()) );
00254 }
00255
00256 glEnd();
00257
00258 getMaterial()->getState()->deactivate(act);
00259
00260 glScalef(1, 1, 1);
00261
00262 if ( getCleanup() )
00263 {
00264 if (bit >= 0)
00265 glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
00266 else
00267 glClear(GL_DEPTH_BUFFER_BIT);
00268 }
00269
00270 glMatrixMode(GL_PROJECTION);
00271 glPopMatrix();
00272 glMatrixMode(GL_MODELVIEW);
00273 glPopMatrix();
00274 glMatrixMode(GL_TEXTURE);
00275 glPopMatrix();
00276
00277 glPopAttrib();
00278 }
00279
00280 void PolygonBackground::changed(BitVector whichField, UInt32 origin)
00281 {
00282 Inherited::changed(whichField, origin);
00283 }
00284
00285 void PolygonBackground::dump( UInt32 ,
00286 const BitVector ) const
00287 {
00288 SLOG << "Dump PolygonBackground NI" << std::endl;
00289 }
00290
00291
00292
00293
00294
00295 #ifdef OSG_SGI_CC
00296 #pragma set woff 1174
00297 #endif
00298
00299 #ifdef OSG_LINUX_ICC
00300 #pragma warning( disable : 177 )
00301 #endif
00302
00303 namespace
00304 {
00305 static Char8 cvsid_cpp [] = "@(#)$Id: OSGPolygonBackground.cpp,v 1.7 2007/03/09 16:59:50 yjung Exp $";
00306 static Char8 cvsid_hpp [] = OSGPOLYGONBACKGROUNDBASE_HEADER_CVSID;
00307 static Char8 cvsid_inl [] = OSGPOLYGONBACKGROUNDBASE_INLINE_CVSID;
00308
00309 static Char8 cvsid_fields_hpp[] = OSGPOLYGONBACKGROUNDFIELDS_HEADER_CVSID;
00310 }
00311
00312 #ifdef __sgi
00313 #pragma reset woff 1174
00314 #endif
00315