1 ////////////////////////////////////////////////////////////////////////////////
2 // Scorched3D (c) 2000-2009
4 // This file is part of Scorched3D.
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()
35 instance_
= new BackdropDialog
;
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()
58 void BackdropDialog::drawBackground()
60 static bool createdTexture
= false;
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())
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
86 glColor3f(1.0f
, 1.0f
, 1.0f
);//0.2f, 0.2f, 0.2f);
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
);
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"),
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
;
122 glColor3f(1.0f
, 1.0f
, 1.0f
);
125 wWidth
- logoWidth
- 50.0f
,
126 wHeight
- logoHeight
- 50.0f
,
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
);
141 void BackdropDialog::drawFooter()
143 static bool createdTexture
= false;
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
);
165 wWidth
- logoWidth
- 10.0f
,
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
);
181 void BackdropDialog::capture()
183 if (OptionsDisplay::instance()->getNoProgressBackdrop()) return;
184 if (!backTex_
.getTexName() == 0) return;
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)
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
++)
218 unsigned char *src2
= src
+ a
* 3 + b
* GLViewPort::getActualWidth() * 3;
219 if (src2
>= screenpixels
&& src2
- screenpixels
< imageSize
)
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];
248 delete [] screenpixels
;
250 backTex_
.replace(handle
, false);