Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 3536 was 3536, checked in by bensch, 19 years ago

orxonox/trunk: GL_TEXTURE_2D-patch: now only enabled and disabled through Material

File size: 6.5 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 "material.h"
22
23using namespace std;
24
25GLMenuImageScreen* GLMenuImageScreen::singletonRef = 0;
26
27GLMenuImageScreen* 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*/
39GLMenuImageScreen::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*/
50GLMenuImageScreen::~GLMenuImageScreen() 
51{
52  if (backMat)
53    delete backMat;
54}
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("../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*/
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  // 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  glBegin(GL_QUADS);
174  glColor3f(0.96, 0.84, 0.34);
175  glVertex2i(barX, barY);
176  glVertex2i(barX + val, barY);
177  glVertex2i(barX + val, barY + barHeight);
178  glVertex2i(barX, barY + barHeight);
179  glColor3f(1.0, 1.0, 1.0);
180  glEnd();
181
182  glBegin(GL_QUADS);
183  glColor3f(0.0, 0.0, 0.0);
184  glVertex2i(barX, barY);
185  glVertex2i(barX + barWidth, barY);
186  glVertex2i(barX + barWidth, barY + barHeight);
187  glVertex2i(barX, barY + barHeight);
188  glColor3f(1.0, 1.0, 1.0);
189  glEnd();
190
191  /* draw black border */
192  glBegin(GL_QUADS);
193  glColor3f(0.0, 0.0, 0.0);
194  glVertex2i(barX-1, barY-1);
195  glVertex2i(barX + barWidth +1, barY-1);
196  glVertex2i(barX + barWidth+1, barY + barHeight+1);
197  glVertex2i(barX - 1, barY + barHeight +1);
198  glColor3f(1.0, 1.0, 1.0);
199  glEnd();
200
201  /* draw white border */
202  glBegin(GL_QUADS);
203  glColor3f(1.0, 1.0, 1.0);
204  glVertex2i(barX-2, barY-2);
205  glVertex2i(barX + barWidth +2, barY-2);
206  glVertex2i(barX + barWidth+2, barY + barHeight+2);
207  glVertex2i(barX - 2, barY + barHeight +2);
208  glColor3f(1.0, 1.0, 1.0);
209  glEnd();
210
211  backMat->select();
212  glBegin(GL_QUADS);
213  glTexCoord2i(0, 0); glVertex2i(offsetX, offsetY);
214  glTexCoord2i(1, 0); glVertex2i(offsetX + imageWidth, offsetY);
215  glTexCoord2i(1, 1); glVertex2i(offsetX + imageWidth, offsetY + imageHeight);
216  glTexCoord2i(0, 1); glVertex2i(offsetX, offsetY + imageHeight);
217  glEnd();
218  glDisable(GL_TEXTURE_2D);
219
220  glDisable(GL_BLEND);
221  glPopMatrix();
222  glMatrixMode(GL_PROJECTION);
223  glPopMatrix();
224  glPopAttrib();
225
226  SDL_GL_SwapBuffers();                   
227}
228 
229
230/**
231    \brief sets the background image name
232    \param file name of the backgroun-image
233 */
234void GLMenuImageScreen::setBackImageName (char* backImageName)
235{}
236
237
238/**
239   \brief sets position of the ImageScreen
240   \param x offset from (0, 0)
241   \param y offset from (0, 0)
242*/
243void GLMenuImageScreen::setPosition(float offsetX, float offsetY)
244{}
245
246
247/*
248  \brief sets size of the ImageScreen
249  \param height of the ImageScreen
250  \param width of the Image Screen
251*/
252void GLMenuImageScreen::setSize(float height, float width)
253{}
254
255
256/**
257   \brief set the maximum of countable steps
258   \param maximum of steps
259*/
260void GLMenuImageScreen::setMaximum(int maxValue)
261{
262  this->maxValue = maxValue;
263}
264
265
266/**
267   \brief gets the maximum of countable steps
268*/
269int GLMenuImageScreen::getMaximum()
270{
271  return this->maxValue;
272}
273
274
275/**
276   \brief set current value
277   \param current value
278*/
279void GLMenuImageScreen::setValue(int currentValue)
280{
281  this->currentValue = currentValue;
282  this->draw();
283}
284
285
286/**
287   \brief get the current value
288 */
289int GLMenuImageScreen::getValue()
290{
291  return this->currentValue;
292}
293
294
295/**
296    \brief call this to trigger a progress event
297   
298    this has to redraw the progress bar and the whole image
299 */
300void GLMenuImageScreen::step ()
301{
302  this->currentValue++;
303  this->draw();
304}
Note: See TracBrowser for help on using the repository browser.