Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 3715 was 3678, checked in by bensch, 20 years ago

orxonox/trunk: deleted class primitive, because model has the same ability now

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