changed: gcc8 base update
[opensg.git] / Source / System / Window / Background / OSGTileableBackground.cpp
blobddf9f42387bc5ce2b2574a5ae2284236b88dc734
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2006 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; if not, 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 "OSGTileableBackground.h"
49 #include "OSGDrawEnv.h"
50 #include "OSGRenderActionBase.h"
51 #include "OSGTileCameraDecorator.h"
52 #include "OSGTextureBaseChunk.h"
54 OSG_BEGIN_NAMESPACE
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 /***************************************************************************\
62 * Class variables *
63 \***************************************************************************/
65 /***************************************************************************\
66 * Class methods *
67 \***************************************************************************/
69 void TileableBackground::initMethod(InitPhase ePhase)
71 Inherited::initMethod(ePhase);
73 if(ePhase == TypeObject::SystemPost)
79 /***************************************************************************\
80 * Instance methods *
81 \***************************************************************************/
83 /*-------------------------------------------------------------------------*\
84 - private -
85 \*-------------------------------------------------------------------------*/
87 /*----------------------- constructors & destructors ----------------------*/
89 TileableBackground::TileableBackground(void) :
90 Inherited()
94 TileableBackground::TileableBackground(const TileableBackground &source) :
95 Inherited(source)
99 TileableBackground::~TileableBackground(void)
103 /*----------------------------- class specific ----------------------------*/
105 void TileableBackground::changed(ConstFieldMaskArg whichField,
106 UInt32 origin,
107 BitVector details)
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(
132 DrawEnv *pEnv,
133 bool normX,
134 bool normY,
135 UInt32 &fullWidth,
136 UInt32 &fullHeight)
138 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
139 glMatrixMode(GL_MODELVIEW);
140 glPushMatrix();
141 glLoadIdentity();
143 TextureBaseChunk::activateTexture(pEnv->getWindow(), 0);
144 glMatrixMode(GL_TEXTURE);
145 glPushMatrix();
146 glLoadIdentity();
148 glMatrixMode(GL_PROJECTION);
149 glPushMatrix();
150 glLoadIdentity();
152 UInt32 width = pEnv->getPixelWidth ();
153 UInt32 height = pEnv->getPixelHeight();
155 fullWidth = pEnv->getTileFullSize()[0];
156 fullHeight = pEnv->getTileFullSize()[1];
158 if(fullWidth == 0)
160 fullWidth = width;
161 fullHeight = height;
163 else
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);
177 #endif
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);
186 glPopMatrix();
188 TextureBaseChunk::activateTexture(pEnv->getWindow(), 0);
189 glMatrixMode(GL_TEXTURE);
190 glPopMatrix();
192 glMatrixMode(GL_MODELVIEW);
193 glPopMatrix();
194 #endif
197 OSG_END_NAMESPACE