Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

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

File size: 6.2 KB
RevLine 
[3357]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"
[3428]20
[3543]21#include "stdincl.h"
[3484]22#include "material.h"
[3357]23
24using namespace std;
25
[3367]26GLMenuImageScreen* GLMenuImageScreen::singletonRef = 0;
[3357]27
[3367]28GLMenuImageScreen* GLMenuImageScreen::getInstance()
29{
[3543]30  if(!singletonRef)
[3367]31    singletonRef = new GLMenuImageScreen ();
32  return singletonRef;
33}
34
[3357]35/**
36   \brief standard constructor
37
38   \todo this constructor is not jet implemented - do it
39*/
40GLMenuImageScreen::GLMenuImageScreen () 
41{
42   this->setClassName ("GLMenuImageScreen");
[3678]43   this->init();
[3357]44}
45
46
47/**
48   \brief standard deconstructor
[3544]49   \todo this deconstructor is not jet implemented - do it
[3543]50*/
51GLMenuImageScreen::~GLMenuImageScreen() 
52{
[3677]53  if (this->backMat)
54    delete this->backMat;
[3394]55}
[3357]56
57/**
58   \brief function to init the screen
59*/
60void GLMenuImageScreen::init ()
[3358]61{
[3361]62  /*
[3358]63  int w = 680;
64  int h = 480;
[3357]65
[3358]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);
[3357]72
[3358]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]);
[3361]79  */
80
81 
82  // Select Our VU Meter Background Texture
[3394]83  this->backMat = new Material("load_screen");
[3658]84  this->backMat->setDiffuseMap("pictures/load_screen.jpg");
[3368]85  this->maxValue = 10;
86  this->currentValue = 0;
87
[3361]88  // End of Background image code.
[3358]89}
90
91
[3357]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 ()
[3358]112{
[3357]113
[3362]114  glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
115
[3729]116  PRINTF(4)("GLMenuImagEscreen::draw() - drawing step %i/%i\n", 
[3675]117         this->currentValue, this->maxValue);
118
[3367]119  /* screen size */
[3364]120  int screenWidth = 640;
121  int screenHeight = 480;
[3361]122 
[3367]123  /* set image size */
[3364]124  int imageWidth = 640;
125  int imageHeight = 480;
[3362]126 
[3367]127  /* start pos of image */
[3364]128  int offsetX = (screenWidth - imageWidth)/2;
129  int offsetY = (screenHeight - imageHeight)/2;
[3362]130 
[3367]131  /* loadbar pos */
[3368]132  int barX = 390;
[3367]133  int barY = 50;
134  int barWidth = 230;
135  int barHeight = 30;
[3675]136 
137  float val = ((float)this->currentValue/(float)this->maxValue) * barWidth;
138  if( val > (float)barWidth)
139    val = (float)barWidth;
[3362]140
141  glMatrixMode(GL_PROJECTION);
142  glPushMatrix();
143  glLoadIdentity();
[3364]144  /* set up an ortho screen */
145  glOrtho(0, screenWidth, 0, screenHeight, -1, 1); 
[3362]146  glMatrixMode(GL_MODELVIEW);
147  glLoadIdentity();
148  glPushMatrix();
[3367]149
[3362]150  glEnable(GL_BLEND);
[3367]151  glPushAttrib(GL_LIGHTING_BIT | GL_TRANSFORM_BIT);
152  glDisable(GL_LIGHTING);
[3362]153
[3675]154  /* draw the progress bar */
[3362]155  glBegin(GL_QUADS);
[3367]156  glColor3f(0.96, 0.84, 0.34);
157  glVertex2i(barX, barY);
[3675]158  glVertex2i(barX + (int)val, barY);
159  glVertex2i(barX + (int)val, barY + barHeight);
[3368]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);
[3367]167  glVertex2i(barX + barWidth, barY);
168  glVertex2i(barX + barWidth, barY + barHeight);
169  glVertex2i(barX, barY + barHeight);
170  glColor3f(1.0, 1.0, 1.0);
[3362]171  glEnd();
172
[3368]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
[3536]193  backMat->select();
[3364]194  glBegin(GL_QUADS);
[3367]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);
[3364]199  glEnd();
[3367]200  glDisable(GL_TEXTURE_2D);
[3364]201
[3362]202  glDisable(GL_BLEND);
203  glPopMatrix();
204  glMatrixMode(GL_PROJECTION);
205  glPopMatrix();
206  glPopAttrib();
207
[3675]208  SDL_GL_SwapBuffers();             
[3358]209}
[3363]210 
[3358]211
[3357]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{}
[3363]236
237
238/**
239   \brief set the maximum of countable steps
240   \param maximum of steps
241*/
[3368]242void GLMenuImageScreen::setMaximum(int maxValue)
[3363]243{
[3368]244  this->maxValue = maxValue;
[3363]245}
246
247
248/**
249   \brief gets the maximum of countable steps
250*/
251int GLMenuImageScreen::getMaximum()
252{
[3368]253  return this->maxValue;
[3363]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++;
[3368]285  this->draw();
[3363]286}
Note: See TracBrowser for help on using the repository browser.