Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/glmenu/glmenu_imagescreen.cc @ 3729

Last change on this file since 3729 was 3729, checked in by patrick, 19 years ago

orxonox/trunk: simple animation is moving, but not realy what it should

File size: 6.2 KB
Line 
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
24using namespace std;
25
26GLMenuImageScreen* GLMenuImageScreen::singletonRef = 0;
27
28GLMenuImageScreen* 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*/
40GLMenuImageScreen::GLMenuImageScreen () 
41{
42   this->setClassName ("GLMenuImageScreen");
43   this->init();
44}
45
46
47/**
48   \brief standard deconstructor
49   \todo this deconstructor is not jet implemented - do it
50*/
51GLMenuImageScreen::~GLMenuImageScreen() 
52{
53  if (this->backMat)
54    delete this->backMat;
55}
56
57/**
58   \brief function to init the screen
59*/
60void 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("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*/
103void 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*/
111void GLMenuImageScreen::draw ()
112{
113
114  glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
115
116  PRINTF(4)("GLMenuImagEscreen::draw() - drawing step %i/%i\n", 
117         this->currentValue, this->maxValue);
118
119  /* screen size */
120  int screenWidth = 640;
121  int screenHeight = 480;
122 
123  /* set image size */
124  int imageWidth = 640;
125  int imageHeight = 480;
126 
127  /* start pos of image */
128  int offsetX = (screenWidth - imageWidth)/2;
129  int offsetY = (screenHeight - imageHeight)/2;
130 
131  /* loadbar pos */
132  int barX = 390;
133  int barY = 50;
134  int barWidth = 230;
135  int barHeight = 30;
136 
137  float val = ((float)this->currentValue/(float)this->maxValue) * barWidth;
138  if( val > (float)barWidth)
139    val = (float)barWidth;
140
141  glMatrixMode(GL_PROJECTION);
142  glPushMatrix();
143  glLoadIdentity();
144  /* set up an ortho screen */
145  glOrtho(0, screenWidth, 0, screenHeight, -1, 1); 
146  glMatrixMode(GL_MODELVIEW);
147  glLoadIdentity();
148  glPushMatrix();
149
150  glEnable(GL_BLEND);
151  glPushAttrib(GL_LIGHTING_BIT | GL_TRANSFORM_BIT);
152  glDisable(GL_LIGHTING);
153
154  /* draw the progress bar */
155  glBegin(GL_QUADS);
156  glColor3f(0.96, 0.84, 0.34);
157  glVertex2i(barX, barY);
158  glVertex2i(barX + (int)val, barY);
159  glVertex2i(barX + (int)val, barY + barHeight);
160  glVertex2i(barX, barY + barHeight);
161  glColor3f(1.0, 1.0, 1.0);
162  glEnd();
163
164  glBegin(GL_QUADS);
165  glColor3f(0.0, 0.0, 0.0);
166  glVertex2i(barX, barY);
167  glVertex2i(barX + barWidth, barY);
168  glVertex2i(barX + barWidth, barY + barHeight);
169  glVertex2i(barX, barY + barHeight);
170  glColor3f(1.0, 1.0, 1.0);
171  glEnd();
172
173  /* draw black border */
174  glBegin(GL_QUADS);
175  glColor3f(0.0, 0.0, 0.0);
176  glVertex2i(barX-1, barY-1);
177  glVertex2i(barX + barWidth +1, barY-1);
178  glVertex2i(barX + barWidth+1, barY + barHeight+1);
179  glVertex2i(barX - 1, barY + barHeight +1);
180  glColor3f(1.0, 1.0, 1.0);
181  glEnd();
182
183  /* draw white border */
184  glBegin(GL_QUADS);
185  glColor3f(1.0, 1.0, 1.0);
186  glVertex2i(barX-2, barY-2);
187  glVertex2i(barX + barWidth +2, barY-2);
188  glVertex2i(barX + barWidth+2, barY + barHeight+2);
189  glVertex2i(barX - 2, barY + barHeight +2);
190  glColor3f(1.0, 1.0, 1.0);
191  glEnd();
192
193  backMat->select();
194  glBegin(GL_QUADS);
195  glTexCoord2i(0, 0); glVertex2i(offsetX, offsetY);
196  glTexCoord2i(1, 0); glVertex2i(offsetX + imageWidth, offsetY);
197  glTexCoord2i(1, 1); glVertex2i(offsetX + imageWidth, offsetY + imageHeight);
198  glTexCoord2i(0, 1); glVertex2i(offsetX, offsetY + imageHeight);
199  glEnd();
200  glDisable(GL_TEXTURE_2D);
201
202  glDisable(GL_BLEND);
203  glPopMatrix();
204  glMatrixMode(GL_PROJECTION);
205  glPopMatrix();
206  glPopAttrib();
207
208  SDL_GL_SwapBuffers();             
209}
210 
211
212/**
213    \brief sets the background image name
214    \param file name of the backgroun-image
215 */
216void GLMenuImageScreen::setBackImageName (char* backImageName)
217{}
218
219
220/**
221   \brief sets position of the ImageScreen
222   \param x offset from (0, 0)
223   \param y offset from (0, 0)
224*/
225void GLMenuImageScreen::setPosition(float offsetX, float offsetY)
226{}
227
228
229/*
230  \brief sets size of the ImageScreen
231  \param height of the ImageScreen
232  \param width of the Image Screen
233*/
234void GLMenuImageScreen::setSize(float height, float width)
235{}
236
237
238/**
239   \brief set the maximum of countable steps
240   \param maximum of steps
241*/
242void GLMenuImageScreen::setMaximum(int maxValue)
243{
244  this->maxValue = maxValue;
245}
246
247
248/**
249   \brief gets the maximum of countable steps
250*/
251int GLMenuImageScreen::getMaximum()
252{
253  return this->maxValue;
254}
255
256
257/**
258   \brief set current value
259   \param current value
260*/
261void GLMenuImageScreen::setValue(int currentValue)
262{
263  this->currentValue = currentValue;
264  this->draw();
265}
266
267
268/**
269   \brief get the current value
270 */
271int GLMenuImageScreen::getValue()
272{
273  return this->currentValue;
274}
275
276
277/**
278    \brief call this to trigger a progress event
279   
280    this has to redraw the progress bar and the whole image
281 */
282void GLMenuImageScreen::step ()
283{
284  this->currentValue++;
285  this->draw();
286}
Note: See TracBrowser for help on using the repository browser.