BackdropDialog.cpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #include <GLEXT/GLViewPort.h>
00022 #include <GLEXT/GLState.h>
00023 #include <image/ImageFactory.h>
00024 #include <graph/Main2DCamera.h>
00025 #include <graph/OptionsDisplay.h>
00026 #include <dialogs/BackdropDialog.h>
00027 #include <common/Defines.h>
00028 
00029 BackdropDialog *BackdropDialog::instance_ = 0;
00030 
00031 BackdropDialog *BackdropDialog::instance()
00032 {
00033         if (!instance_)
00034         {
00035                 instance_ = new BackdropDialog;
00036         }
00037         return instance_;
00038 }
00039 
00040 BackdropDialog::BackdropDialog() : 
00041         GLWWindow("", 0.0f, 0.0f, 0.0f, 0.0f, 0,
00042                 "The backdrop dialog")
00043 {
00044         windowLevel_ = 5000000;
00045 }
00046 
00047 BackdropDialog::~BackdropDialog()
00048 {
00049 }
00050 
00051 void BackdropDialog::draw()
00052 {
00053         drawBackground();
00054         drawLogo();
00055         drawFooter();
00056 }
00057 
00058 void BackdropDialog::drawBackground()
00059 {
00060         static bool createdTexture = false;
00061         if (!createdTexture)
00062         {
00063                 createdTexture = true;
00064                 ImageHandle originalBackMap = ImageFactory::loadImageHandle(
00065                         S3D::getDataFile("data/windows/backdrop.jpg"));
00066                 int w = originalBackMap.getWidth();
00067                 int h = originalBackMap.getHeight();
00068                 while (w > GLViewPort::getActualWidth() || h > GLViewPort::getActualHeight())
00069                 {
00070                         w /= 2;
00071                         h /= 2;
00072                 }
00073 
00074                 ImageHandle backMap = originalBackMap.createResize(w, h);
00075                 backTex_.create(backMap, false);
00076         }
00077 
00078         GLState currentState(GLState::DEPTH_OFF | GLState::TEXTURE_ON);
00079 
00080         // Calcuate how may tiles are needed
00081         float wWidth = (float) GLViewPort::getWidth();
00082         float wHeight = (float) GLViewPort::getHeight();
00083 
00084         // Draw the tiled logo backdrop
00085         backTex_.draw(true);
00086         glColor3f(1.0f, 1.0f, 1.0f);//0.2f, 0.2f, 0.2f);
00087         glBegin(GL_QUADS);
00088                 glTexCoord2f(0.0f, 0.0f);
00089                 glVertex2f(0.0f, 0.0f);
00090                 glTexCoord2f(1.0f, 0.0f);
00091                 glVertex2f(wWidth, 0.0f);
00092                 glTexCoord2f(1.0f, 1.0f);
00093                 glVertex2f(wWidth, wHeight);
00094                 glTexCoord2f(0.0f, 1.0f);
00095                 glVertex2f(0.0f, wHeight);
00096         glEnd();        
00097 }
00098 
00099 void BackdropDialog::drawLogo()
00100 {
00101         if (S3D::getDataFileMod() != lastMod_)
00102         {
00103                 lastMod_ = S3D::getDataFileMod();
00104 
00105                 ImageHandle logoMap = ImageFactory::loadImageHandle(
00106                         S3D::getDataFile("data/windows/scorched.jpg"),
00107                         S3D::getDataFile("data/windows/scorcheda.jpg"),
00108                         false);
00109                 logoTex_.create(logoMap, false);
00110         }
00111 
00112         GLState currentState(GLState::DEPTH_OFF | GLState::BLEND_ON | GLState::TEXTURE_ON);
00113 
00114         // Calcuate how may tiles are needed
00115         float wWidth = (float) GLViewPort::getWidth();
00116         float wHeight = (float) GLViewPort::getHeight();
00117 
00118         // Draw the higer rez logo
00119         const float logoWidth = 480.0f;
00120         const float logoHeight = 90.0f;
00121         logoTex_.draw(true);
00122         glColor3f(1.0f, 1.0f, 1.0f);
00123         glPushMatrix();
00124                 glTranslatef(
00125                         wWidth - logoWidth - 50.0f, 
00126                         wHeight - logoHeight - 50.0f, 
00127                         0.0f);
00128                 glBegin(GL_QUADS);
00129                         glTexCoord2f(0.0f, 0.0f);
00130                         glVertex2f(0.0f, 0.0f);
00131                         glTexCoord2f(1.0f, 0.0f);
00132                         glVertex2f(logoWidth, 0.0f);
00133                         glTexCoord2f(1.0f, 1.0f);
00134                         glVertex2f(logoWidth, logoHeight);
00135                         glTexCoord2f(0.0f, 1.0f);
00136                         glVertex2f(0.0f, logoHeight);
00137                 glEnd();
00138         glPopMatrix();
00139 }
00140 
00141 void BackdropDialog::drawFooter()
00142 {
00143         static bool createdTexture = false;
00144         if (!createdTexture)
00145         {
00146                 createdTexture = true;
00147                 ImageHandle logoMap = ImageFactory::loadAlphaImageHandle(
00148                         S3D::getDataFile("data/windows/hiscore.png"));
00149                 footerTex_.create(logoMap, false);
00150         }
00151 
00152         GLState currentState(GLState::DEPTH_OFF | GLState::BLEND_ON | GLState::TEXTURE_ON);
00153 
00154         // Calcuate how may tiles are needed
00155         float wWidth = (float) GLViewPort::getWidth();
00156         float wHeight = (float) GLViewPort::getHeight();
00157 
00158         // Draw the higer rez logo
00159         const float logoWidth = 200.0f;
00160         const float logoHeight = 90.0f;
00161         footerTex_.draw(true);
00162         glColor4f(1.0f, 1.0f, 1.0f, 0.6f);
00163         glPushMatrix();
00164                 glTranslatef(
00165                         wWidth - logoWidth - 10.0f,
00166                         10.0f, 
00167                         0.0f);
00168                 glBegin(GL_QUADS);
00169                         glTexCoord2f(0.0f, 0.0f);
00170                         glVertex2f(0.0f, 0.0f);
00171                         glTexCoord2f(1.0f, 0.0f);
00172                         glVertex2f(logoWidth, 0.0f);
00173                         glTexCoord2f(1.0f, 1.0f);
00174                         glVertex2f(logoWidth, logoHeight);
00175                         glTexCoord2f(0.0f, 1.0f);
00176                         glVertex2f(0.0f, logoHeight);
00177                 glEnd();
00178         glPopMatrix();
00179 }
00180 
00181 void BackdropDialog::capture()
00182 {
00183         if (OptionsDisplay::instance()->getNoProgressBackdrop()) return;
00184         if (!backTex_.getTexName() == 0) return;
00185 
00186         glRasterPos2i(0, 0);
00187 
00188         glPixelStorei(GL_PACK_ALIGNMENT, 4);
00189         glPixelStorei(GL_PACK_ROW_LENGTH, 0);
00190         glPixelStorei(GL_PACK_SKIP_ROWS, 0);
00191         glPixelStorei(GL_PACK_SKIP_PIXELS, 0);
00192 
00193         int imageSize = GLViewPort::getActualWidth() * GLViewPort::getActualHeight() * 3;
00194         unsigned char *screenpixels = new unsigned char[imageSize];
00195         glReadPixels(0, 0, GLViewPort::getActualWidth(), GLViewPort::getActualHeight(), 
00196                 GL_RGB, GL_UNSIGNED_BYTE, screenpixels);
00197 
00198         ImageHandle handle = ImageFactory::createBlank(
00199                 backTex_.getWidth(), backTex_.getHeight());
00200 
00201         unsigned char *src = screenpixels;
00202         for (int y=0; y<GLViewPort::getActualHeight(); y++)
00203         {
00204                 for (int x=0; x<GLViewPort::getActualWidth(); x++, src+=3)
00205                 {
00206                         int totalr = 0;
00207                         int totalg = 0;
00208                         int totalb = 0;
00209                         if (x>=3 && x<GLViewPort::getActualWidth()-3 &&
00210                                 y>=3 && y<GLViewPort::getActualHeight()-3)
00211                         {
00212                                 for (int a=-3; a<=3; a++)
00213                                 {
00214                                         for (int b=-3; b<=3; b++)
00215                                         {
00216                                                 int srcx = a + x;
00217                                                 int srcy = b + y;
00218                                                 unsigned char *src2 = src + a * 3 + b * GLViewPort::getActualWidth() * 3;
00219                                                 if (src2 >= screenpixels && src2 - screenpixels < imageSize)
00220                                                 {
00221                                                         totalr += src2[0];
00222                                                         totalg += src2[1];
00223                                                         totalb += src2[2];
00224                                                 }
00225                                         }
00226                                 }
00227                                 totalr /= 49;
00228                                 totalg /= 49;
00229                                 totalb /= 49;
00230                         }
00231                         else
00232                         {
00233                                 totalr = src[0];
00234                                 totalg = src[1];
00235                                 totalb = src[2];
00236                         }
00237 
00238                         int destx = (x * backTex_.getWidth() / GLViewPort::getActualWidth()) % backTex_.getWidth();
00239                         int desty = (y * backTex_.getHeight() / GLViewPort::getActualHeight()) % backTex_.getHeight();
00240                         unsigned char *dest = &handle.getBits()[destx * 3 + desty * backTex_.getWidth() * 3];
00241 
00242                         dest[0] = totalr;
00243                         dest[1] = totalg;
00244                         dest[2] = totalb;
00245                 }
00246         }
00247 
00248         delete [] screenpixels;
00249 
00250         backTex_.replace(handle, false);
00251 }

Generated on Mon Feb 16 15:14:37 2009 for Scorched3D by  doxygen 1.5.3