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