1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2006 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"
48 #include "OSGTileableBackground.h"
49 #include "OSGDrawEnv.h"
50 #include "OSGRenderActionBase.h"
51 #include "OSGTileCameraDecorator.h"
52 #include "OSGTextureBaseChunk.h"
56 // Documentation for this class is emitted in the
57 // OSGTileableBackgroundBase.cpp file.
58 // To modify it, please change the .fcd file (OSGTileableBackground.fcd) and
59 // regenerate the base file.
61 /***************************************************************************\
63 \***************************************************************************/
65 /***************************************************************************\
67 \***************************************************************************/
69 void TileableBackground::initMethod(InitPhase ePhase
)
71 Inherited::initMethod(ePhase
);
73 if(ePhase
== TypeObject::SystemPost
)
79 /***************************************************************************\
81 \***************************************************************************/
83 /*-------------------------------------------------------------------------*\
85 \*-------------------------------------------------------------------------*/
87 /*----------------------- constructors & destructors ----------------------*/
89 TileableBackground::TileableBackground(void) :
94 TileableBackground::TileableBackground(const TileableBackground
&source
) :
99 TileableBackground::~TileableBackground(void)
103 /*----------------------------- class specific ----------------------------*/
105 void TileableBackground::changed(ConstFieldMaskArg whichField
,
109 Inherited::changed(whichField
, origin
, details
);
112 void TileableBackground::dump( UInt32
,
113 const BitVector
) const
115 SLOG
<< "Dump TileableBackground NI" << std::endl
;
118 /*! Sets up an ortho projection for rendering 2D backgrounds. It handles tiling
119 when a TileCameraDecorator is in use. When done you need to call
120 endOrthoRender to clean up changes to the OpenGL matrix stacks.
122 \param pEnv DrawEnv being used for rendering
123 \param normX Wether x coordinates are going to be normalized.
124 \param normY Wether y coordinates are going to be normalized.
125 \param[out] fullWidth width of the viewport
126 \param[out] fullHeight height of the viewport
128 \note When the TileCameraDecorator is in use, the width and height of the
129 viewport (fullWidth, fullHeight) are defined by the TileCameraDecorator.
131 void TileableBackground::beginOrthoRender(
138 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
139 glMatrixMode(GL_MODELVIEW
);
143 TextureBaseChunk::activateTexture(pEnv
->getWindow(), 0);
144 glMatrixMode(GL_TEXTURE
);
148 glMatrixMode(GL_PROJECTION
);
152 UInt32 width
= pEnv
->getPixelWidth ();
153 UInt32 height
= pEnv
->getPixelHeight();
155 fullWidth
= pEnv
->getTileFullSize()[0];
156 fullHeight
= pEnv
->getTileFullSize()[1];
165 if(getTile() == false)
167 Matrix sm
= pEnv
->calcTileDecorationMatrix();
169 glLoadMatrixf(sm
.getValues());
173 Real32 projWidth
= normX
? 1.0f
: Real32(width
);
174 Real32 projHeight
= normY
? 1.0f
: Real32(height
);
176 glOrtho(0, projWidth
, 0, projHeight
, -1.0f
, 1.0f
);
180 /*! Clean up changes to the OpenGL matrix stacks done by beginOrthoRender
182 void TileableBackground::endOrthoRender(DrawEnv
*pEnv
)
184 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
185 glMatrixMode(GL_PROJECTION
);
188 TextureBaseChunk::activateTexture(pEnv
->getWindow(), 0);
189 glMatrixMode(GL_TEXTURE
);
192 glMatrixMode(GL_MODELVIEW
);