git-svn-id: https://scorched3d.svn.sourceforge.net/svnroot/scorched3d/trunk/scorched...
[scorched3d/parasti.git] / src / client / dialogs / BackdropDialog.cpp
blob0ada3fd7b2d8e03efc6e884f1c98efd356c718fd
1 ////////////////////////////////////////////////////////////////////////////////
2 // Scorched3D (c) 2000-2009
3 //
4 // This file is part of Scorched3D.
5 //
6 // Scorched3D is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // Scorched3D is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with Scorched3D; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ////////////////////////////////////////////////////////////////////////////////
21 #include <GLEXT/GLViewPort.h>
22 #include <GLEXT/GLState.h>
23 #include <image/ImageFactory.h>
24 #include <graph/Main2DCamera.h>
25 #include <graph/OptionsDisplay.h>
26 #include <dialogs/BackdropDialog.h>
27 #include <common/Defines.h>
29 BackdropDialog *BackdropDialog::instance_ = 0;
31 BackdropDialog *BackdropDialog::instance()
33 if (!instance_)
35 instance_ = new BackdropDialog;
37 return instance_;
40 BackdropDialog::BackdropDialog() :
41 GLWWindow("", 0.0f, 0.0f, 0.0f, 0.0f, 0,
42 "The backdrop dialog")
44 windowLevel_ = 5000000;
47 BackdropDialog::~BackdropDialog()
51 void BackdropDialog::draw()
53 drawBackground();
54 drawLogo();
55 drawFooter();
58 void BackdropDialog::drawBackground()
60 static bool createdTexture = false;
61 if (!createdTexture)
63 createdTexture = true;
64 ImageHandle originalBackMap = ImageFactory::loadImageHandle(
65 S3D::getDataFile("data/windows/backdrop.jpg"));
66 int w = originalBackMap.getWidth();
67 int h = originalBackMap.getHeight();
68 while (w > GLViewPort::getActualWidth() || h > GLViewPort::getActualHeight())
70 w /= 2;
71 h /= 2;
74 ImageHandle backMap = originalBackMap.createResize(w, h);
75 backTex_.create(backMap, false);
78 GLState currentState(GLState::DEPTH_OFF | GLState::TEXTURE_ON);
80 // Calcuate how may tiles are needed
81 float wWidth = (float) GLViewPort::getWidth();
82 float wHeight = (float) GLViewPort::getHeight();
84 // Draw the tiled logo backdrop
85 backTex_.draw(true);
86 glColor3f(1.0f, 1.0f, 1.0f);//0.2f, 0.2f, 0.2f);
87 glBegin(GL_QUADS);
88 glTexCoord2f(0.0f, 0.0f);
89 glVertex2f(0.0f, 0.0f);
90 glTexCoord2f(1.0f, 0.0f);
91 glVertex2f(wWidth, 0.0f);
92 glTexCoord2f(1.0f, 1.0f);
93 glVertex2f(wWidth, wHeight);
94 glTexCoord2f(0.0f, 1.0f);
95 glVertex2f(0.0f, wHeight);
96 glEnd();
99 void BackdropDialog::drawLogo()
101 if (S3D::getDataFileMod() != lastMod_)
103 lastMod_ = S3D::getDataFileMod();
105 ImageHandle logoMap = ImageFactory::loadImageHandle(
106 S3D::getDataFile("data/windows/scorched.jpg"),
107 S3D::getDataFile("data/windows/scorcheda.jpg"),
108 false);
109 logoTex_.create(logoMap, false);
112 GLState currentState(GLState::DEPTH_OFF | GLState::BLEND_ON | GLState::TEXTURE_ON);
114 // Calcuate how may tiles are needed
115 float wWidth = (float) GLViewPort::getWidth();
116 float wHeight = (float) GLViewPort::getHeight();
118 // Draw the higer rez logo
119 const float logoWidth = 480.0f;
120 const float logoHeight = 90.0f;
121 logoTex_.draw(true);
122 glColor3f(1.0f, 1.0f, 1.0f);
123 glPushMatrix();
124 glTranslatef(
125 wWidth - logoWidth - 50.0f,
126 wHeight - logoHeight - 50.0f,
127 0.0f);
128 glBegin(GL_QUADS);
129 glTexCoord2f(0.0f, 0.0f);
130 glVertex2f(0.0f, 0.0f);
131 glTexCoord2f(1.0f, 0.0f);
132 glVertex2f(logoWidth, 0.0f);
133 glTexCoord2f(1.0f, 1.0f);
134 glVertex2f(logoWidth, logoHeight);
135 glTexCoord2f(0.0f, 1.0f);
136 glVertex2f(0.0f, logoHeight);
137 glEnd();
138 glPopMatrix();
141 void BackdropDialog::drawFooter()
143 static bool createdTexture = false;
144 if (!createdTexture)
146 createdTexture = true;
147 ImageHandle logoMap = ImageFactory::loadAlphaImageHandle(
148 S3D::getDataFile("data/windows/hiscore.png"));
149 footerTex_.create(logoMap, false);
152 GLState currentState(GLState::DEPTH_OFF | GLState::BLEND_ON | GLState::TEXTURE_ON);
154 // Calcuate how may tiles are needed
155 float wWidth = (float) GLViewPort::getWidth();
156 float wHeight = (float) GLViewPort::getHeight();
158 // Draw the higer rez logo
159 const float logoWidth = 200.0f;
160 const float logoHeight = 90.0f;
161 footerTex_.draw(true);
162 glColor4f(1.0f, 1.0f, 1.0f, 0.6f);
163 glPushMatrix();
164 glTranslatef(
165 wWidth - logoWidth - 10.0f,
166 10.0f,
167 0.0f);
168 glBegin(GL_QUADS);
169 glTexCoord2f(0.0f, 0.0f);
170 glVertex2f(0.0f, 0.0f);
171 glTexCoord2f(1.0f, 0.0f);
172 glVertex2f(logoWidth, 0.0f);
173 glTexCoord2f(1.0f, 1.0f);
174 glVertex2f(logoWidth, logoHeight);
175 glTexCoord2f(0.0f, 1.0f);
176 glVertex2f(0.0f, logoHeight);
177 glEnd();
178 glPopMatrix();
181 void BackdropDialog::capture()
183 if (OptionsDisplay::instance()->getNoProgressBackdrop()) return;
184 if (!backTex_.getTexName() == 0) return;
186 glRasterPos2i(0, 0);
188 glPixelStorei(GL_PACK_ALIGNMENT, 4);
189 glPixelStorei(GL_PACK_ROW_LENGTH, 0);
190 glPixelStorei(GL_PACK_SKIP_ROWS, 0);
191 glPixelStorei(GL_PACK_SKIP_PIXELS, 0);
193 int imageSize = GLViewPort::getActualWidth() * GLViewPort::getActualHeight() * 3;
194 unsigned char *screenpixels = new unsigned char[imageSize];
195 glReadPixels(0, 0, GLViewPort::getActualWidth(), GLViewPort::getActualHeight(),
196 GL_RGB, GL_UNSIGNED_BYTE, screenpixels);
198 ImageHandle handle = ImageFactory::createBlank(
199 backTex_.getWidth(), backTex_.getHeight());
201 unsigned char *src = screenpixels;
202 for (int y=0; y<GLViewPort::getActualHeight(); y++)
204 for (int x=0; x<GLViewPort::getActualWidth(); x++, src+=3)
206 int totalr = 0;
207 int totalg = 0;
208 int totalb = 0;
209 if (x>=3 && x<GLViewPort::getActualWidth()-3 &&
210 y>=3 && y<GLViewPort::getActualHeight()-3)
212 for (int a=-3; a<=3; a++)
214 for (int b=-3; b<=3; b++)
216 int srcx = a + x;
217 int srcy = b + y;
218 unsigned char *src2 = src + a * 3 + b * GLViewPort::getActualWidth() * 3;
219 if (src2 >= screenpixels && src2 - screenpixels < imageSize)
221 totalr += src2[0];
222 totalg += src2[1];
223 totalb += src2[2];
227 totalr /= 49;
228 totalg /= 49;
229 totalb /= 49;
231 else
233 totalr = src[0];
234 totalg = src[1];
235 totalb = src[2];
238 int destx = (x * backTex_.getWidth() / GLViewPort::getActualWidth()) % backTex_.getWidth();
239 int desty = (y * backTex_.getHeight() / GLViewPort::getActualHeight()) % backTex_.getHeight();
240 unsigned char *dest = &handle.getBits()[destx * 3 + desty * backTex_.getWidth() * 3];
242 dest[0] = totalr;
243 dest[1] = totalg;
244 dest[2] = totalb;
248 delete [] screenpixels;
250 backTex_.replace(handle, false);