1 | |
---|
2 | |
---|
3 | /* |
---|
4 | orxonox - the future of 3D-vertical-scrollers |
---|
5 | |
---|
6 | Copyright (C) 2004 orx |
---|
7 | |
---|
8 | This program is free software; you can redistribute it and/or modify |
---|
9 | it under the terms of the GNU General Public License as published by |
---|
10 | the Free Software Foundation; either version 2, or (at your option) |
---|
11 | any later version. |
---|
12 | |
---|
13 | ### File Specific: |
---|
14 | main-programmer: Patrick Boenzli |
---|
15 | co-programmer: |
---|
16 | */ |
---|
17 | |
---|
18 | |
---|
19 | #include "glmenu_imagescreen.h" |
---|
20 | |
---|
21 | #include "stdincl.h" |
---|
22 | #include "material.h" |
---|
23 | |
---|
24 | using namespace std; |
---|
25 | |
---|
26 | GLMenuImageScreen* GLMenuImageScreen::singletonRef = 0; |
---|
27 | |
---|
28 | GLMenuImageScreen* GLMenuImageScreen::getInstance() |
---|
29 | { |
---|
30 | if(!singletonRef) |
---|
31 | singletonRef = new GLMenuImageScreen (); |
---|
32 | return singletonRef; |
---|
33 | } |
---|
34 | |
---|
35 | /** |
---|
36 | \brief standard constructor |
---|
37 | |
---|
38 | \todo this constructor is not jet implemented - do it |
---|
39 | */ |
---|
40 | GLMenuImageScreen::GLMenuImageScreen () |
---|
41 | { |
---|
42 | this->setClassName ("GLMenuImageScreen"); |
---|
43 | } |
---|
44 | |
---|
45 | |
---|
46 | /** |
---|
47 | \brief standard deconstructor |
---|
48 | */ |
---|
49 | GLMenuImageScreen::~GLMenuImageScreen() |
---|
50 | { |
---|
51 | this->destroy(); |
---|
52 | } |
---|
53 | |
---|
54 | /** |
---|
55 | \brief deletes all alocated Memory and also deletes everything from the Class this one is erived from |
---|
56 | |
---|
57 | \todo this deconstructor is not jet implemented - do it |
---|
58 | */ |
---|
59 | void GLMenuImageScreen::destroy(void) |
---|
60 | { |
---|
61 | if (backMat) |
---|
62 | delete backMat; |
---|
63 | |
---|
64 | static_cast<BaseObject*>(this)->destroy(); |
---|
65 | } |
---|
66 | |
---|
67 | /** |
---|
68 | \brief function to init the screen |
---|
69 | */ |
---|
70 | void GLMenuImageScreen::init () |
---|
71 | { |
---|
72 | /* |
---|
73 | int w = 680; |
---|
74 | int h = 480; |
---|
75 | |
---|
76 | glViewport(0,0,w,h); |
---|
77 | |
---|
78 | glMatrixMode(GL_PROJECTION); |
---|
79 | glLoadIdentity(); |
---|
80 | gluPerspective(45.0f,(GLfloat)w/(GLfloat)h, .5f ,150.0f); |
---|
81 | glMatrixMode(GL_MODELVIEW); |
---|
82 | |
---|
83 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
---|
84 | glLoadIdentity(); |
---|
85 | gluLookAt(0, 0, 6, 0, 0, 0, 0, 1, 0); |
---|
86 | |
---|
87 | // Bind the texture stored at the zero index of g_Texture[] |
---|
88 | //glBindTexture(GL_TEXTURE_2D, g_Texture[0]); |
---|
89 | */ |
---|
90 | |
---|
91 | |
---|
92 | // Select Our VU Meter Background Texture |
---|
93 | this->backMat = new Material("load_screen"); |
---|
94 | this->backMat->setDiffuseMap("../data/pictures/load_screen.jpg"); |
---|
95 | this->maxValue = 10; |
---|
96 | this->currentValue = 0; |
---|
97 | |
---|
98 | // End of Background image code. |
---|
99 | } |
---|
100 | |
---|
101 | |
---|
102 | /** |
---|
103 | \brief function to innit screen with all attributes set |
---|
104 | \param name of the background-image file |
---|
105 | \param height of the ImageScreen |
---|
106 | \param width of the Image Screen |
---|
107 | \param x offset from (0, 0) |
---|
108 | \param y offset from (0, 0) |
---|
109 | |
---|
110 | GLMenu uses its own coordinating system: upper left corner is (0, 0). x-axis is down=height, |
---|
111 | right axis is right direction (=width) |
---|
112 | */ |
---|
113 | void GLMenuImageScreen::init (char* backImageName, float height, float width, |
---|
114 | float offsetX, float offsetY) |
---|
115 | {} |
---|
116 | |
---|
117 | |
---|
118 | /** |
---|
119 | \brief draws the ImageScreen to the screenbuffer |
---|
120 | */ |
---|
121 | void GLMenuImageScreen::draw () |
---|
122 | { |
---|
123 | /* |
---|
124 | // Display a quad texture to the screen |
---|
125 | glEnable(GL_TEXTURE_2D); |
---|
126 | glBegin(GL_QUADS); |
---|
127 | |
---|
128 | // Display the top left vertice |
---|
129 | glTexCoord2f(0.0f, 1.0f); |
---|
130 | glVertex3f(-2.5, 2.5, 0); |
---|
131 | |
---|
132 | // Display the bottom left vertice |
---|
133 | glTexCoord2f(0.0f, 0.0f); |
---|
134 | glVertex3f(-2.5, -2.5, 0); |
---|
135 | |
---|
136 | // Display the bottom right vertice |
---|
137 | glTexCoord2f(1.0f, 0.0f); |
---|
138 | glVertex3f(2.5, -2.5, 0); |
---|
139 | |
---|
140 | // Display the top right vertice |
---|
141 | glTexCoord2f(1.0f, 1.0f); |
---|
142 | glVertex3f(2.5, 2.5, 0); |
---|
143 | |
---|
144 | glEnd(); |
---|
145 | glEnable(GL_TEXTURE_2D); |
---|
146 | */ |
---|
147 | |
---|
148 | glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); |
---|
149 | |
---|
150 | /* screen size */ |
---|
151 | int screenWidth = 640; |
---|
152 | int screenHeight = 480; |
---|
153 | |
---|
154 | /* set image size */ |
---|
155 | int imageWidth = 640; |
---|
156 | int imageHeight = 480; |
---|
157 | |
---|
158 | /* start pos of image */ |
---|
159 | int offsetX = (screenWidth - imageWidth)/2; |
---|
160 | int offsetY = (screenHeight - imageHeight)/2; |
---|
161 | |
---|
162 | /* loadbar pos */ |
---|
163 | int barX = 390; |
---|
164 | int barY = 50; |
---|
165 | int barWidth = 230; |
---|
166 | int barHeight = 30; |
---|
167 | |
---|
168 | int val = (int)((float)this->currentValue/(float)this->maxValue) * barWidth; |
---|
169 | |
---|
170 | glMatrixMode(GL_PROJECTION); |
---|
171 | glPushMatrix(); |
---|
172 | glLoadIdentity(); |
---|
173 | /* set up an ortho screen */ |
---|
174 | glOrtho(0, screenWidth, 0, screenHeight, -1, 1); |
---|
175 | glMatrixMode(GL_MODELVIEW); |
---|
176 | glLoadIdentity(); |
---|
177 | glPushMatrix(); |
---|
178 | |
---|
179 | glEnable(GL_BLEND); |
---|
180 | glPushAttrib(GL_LIGHTING_BIT | GL_TRANSFORM_BIT); |
---|
181 | glDisable(GL_LIGHTING); |
---|
182 | |
---|
183 | glBegin(GL_QUADS); |
---|
184 | glColor3f(0.96, 0.84, 0.34); |
---|
185 | glVertex2i(barX, barY); |
---|
186 | glVertex2i(barX + val, barY); |
---|
187 | glVertex2i(barX + val, barY + barHeight); |
---|
188 | glVertex2i(barX, barY + barHeight); |
---|
189 | glColor3f(1.0, 1.0, 1.0); |
---|
190 | glEnd(); |
---|
191 | |
---|
192 | glBegin(GL_QUADS); |
---|
193 | glColor3f(0.0, 0.0, 0.0); |
---|
194 | glVertex2i(barX, barY); |
---|
195 | glVertex2i(barX + barWidth, barY); |
---|
196 | glVertex2i(barX + barWidth, barY + barHeight); |
---|
197 | glVertex2i(barX, barY + barHeight); |
---|
198 | glColor3f(1.0, 1.0, 1.0); |
---|
199 | glEnd(); |
---|
200 | |
---|
201 | /* draw black border */ |
---|
202 | glBegin(GL_QUADS); |
---|
203 | glColor3f(0.0, 0.0, 0.0); |
---|
204 | glVertex2i(barX-1, barY-1); |
---|
205 | glVertex2i(barX + barWidth +1, barY-1); |
---|
206 | glVertex2i(barX + barWidth+1, barY + barHeight+1); |
---|
207 | glVertex2i(barX - 1, barY + barHeight +1); |
---|
208 | glColor3f(1.0, 1.0, 1.0); |
---|
209 | glEnd(); |
---|
210 | |
---|
211 | /* draw white border */ |
---|
212 | glBegin(GL_QUADS); |
---|
213 | glColor3f(1.0, 1.0, 1.0); |
---|
214 | glVertex2i(barX-2, barY-2); |
---|
215 | glVertex2i(barX + barWidth +2, barY-2); |
---|
216 | glVertex2i(barX + barWidth+2, barY + barHeight+2); |
---|
217 | glVertex2i(barX - 2, barY + barHeight +2); |
---|
218 | glColor3f(1.0, 1.0, 1.0); |
---|
219 | glEnd(); |
---|
220 | |
---|
221 | backMat->select(); |
---|
222 | glBegin(GL_QUADS); |
---|
223 | glTexCoord2i(0, 0); glVertex2i(offsetX, offsetY); |
---|
224 | glTexCoord2i(1, 0); glVertex2i(offsetX + imageWidth, offsetY); |
---|
225 | glTexCoord2i(1, 1); glVertex2i(offsetX + imageWidth, offsetY + imageHeight); |
---|
226 | glTexCoord2i(0, 1); glVertex2i(offsetX, offsetY + imageHeight); |
---|
227 | glEnd(); |
---|
228 | glDisable(GL_TEXTURE_2D); |
---|
229 | |
---|
230 | glDisable(GL_BLEND); |
---|
231 | glPopMatrix(); |
---|
232 | glMatrixMode(GL_PROJECTION); |
---|
233 | glPopMatrix(); |
---|
234 | glPopAttrib(); |
---|
235 | |
---|
236 | SDL_GL_SwapBuffers(); |
---|
237 | } |
---|
238 | |
---|
239 | |
---|
240 | /** |
---|
241 | \brief sets the background image name |
---|
242 | \param file name of the backgroun-image |
---|
243 | */ |
---|
244 | void GLMenuImageScreen::setBackImageName (char* backImageName) |
---|
245 | {} |
---|
246 | |
---|
247 | |
---|
248 | /** |
---|
249 | \brief sets position of the ImageScreen |
---|
250 | \param x offset from (0, 0) |
---|
251 | \param y offset from (0, 0) |
---|
252 | */ |
---|
253 | void GLMenuImageScreen::setPosition(float offsetX, float offsetY) |
---|
254 | {} |
---|
255 | |
---|
256 | |
---|
257 | /* |
---|
258 | \brief sets size of the ImageScreen |
---|
259 | \param height of the ImageScreen |
---|
260 | \param width of the Image Screen |
---|
261 | */ |
---|
262 | void GLMenuImageScreen::setSize(float height, float width) |
---|
263 | {} |
---|
264 | |
---|
265 | |
---|
266 | /** |
---|
267 | \brief set the maximum of countable steps |
---|
268 | \param maximum of steps |
---|
269 | */ |
---|
270 | void GLMenuImageScreen::setMaximum(int maxValue) |
---|
271 | { |
---|
272 | this->maxValue = maxValue; |
---|
273 | } |
---|
274 | |
---|
275 | |
---|
276 | /** |
---|
277 | \brief gets the maximum of countable steps |
---|
278 | */ |
---|
279 | int GLMenuImageScreen::getMaximum() |
---|
280 | { |
---|
281 | return this->maxValue; |
---|
282 | } |
---|
283 | |
---|
284 | |
---|
285 | /** |
---|
286 | \brief set current value |
---|
287 | \param current value |
---|
288 | */ |
---|
289 | void GLMenuImageScreen::setValue(int currentValue) |
---|
290 | { |
---|
291 | this->currentValue = currentValue; |
---|
292 | this->draw(); |
---|
293 | } |
---|
294 | |
---|
295 | |
---|
296 | /** |
---|
297 | \brief get the current value |
---|
298 | */ |
---|
299 | int GLMenuImageScreen::getValue() |
---|
300 | { |
---|
301 | return this->currentValue; |
---|
302 | } |
---|
303 | |
---|
304 | |
---|
305 | /** |
---|
306 | \brief call this to trigger a progress event |
---|
307 | |
---|
308 | this has to redraw the progress bar and the whole image |
---|
309 | */ |
---|
310 | void GLMenuImageScreen::step () |
---|
311 | { |
---|
312 | this->currentValue++; |
---|
313 | this->draw(); |
---|
314 | } |
---|