Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: glmenu progressbar corrected, pnode modifications

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