Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

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

File size: 6.5 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
[3484]21#include "material.h"
[3357]22
23using namespace std;
24
[3367]25GLMenuImageScreen* GLMenuImageScreen::singletonRef = 0;
[3357]26
[3367]27GLMenuImageScreen* GLMenuImageScreen::getInstance()
28{
29  if( singletonRef == NULL)
30    singletonRef = new GLMenuImageScreen ();
31  return singletonRef;
32}
33
[3357]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*/
[3394]50GLMenuImageScreen::~GLMenuImageScreen() 
51{
52  if (backMat)
53    delete backMat;
54}
[3357]55
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");
84  this->backMat->setDiffuseMap("../data/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{
[3361]113  /*
[3358]114  // Display a quad texture to the screen
[3359]115  glEnable(GL_TEXTURE_2D);
[3358]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);
[3357]133
[3358]134  glEnd();
[3359]135  glEnable(GL_TEXTURE_2D); 
[3361]136  */
[3362]137
138  glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
139
[3367]140  /* screen size */
[3364]141  int screenWidth = 640;
142  int screenHeight = 480;
[3361]143 
[3367]144  /* set image size */
[3364]145  int imageWidth = 640;
146  int imageHeight = 480;
[3362]147 
[3367]148  /* start pos of image */
[3364]149  int offsetX = (screenWidth - imageWidth)/2;
150  int offsetY = (screenHeight - imageHeight)/2;
[3362]151 
[3367]152  /* loadbar pos */
[3368]153  int barX = 390;
[3367]154  int barY = 50;
155  int barWidth = 230;
156  int barHeight = 30;
[3362]157
[3428]158  int val = (int)((float)this->currentValue/(float)this->maxValue) * barWidth;
[3368]159
[3362]160  glMatrixMode(GL_PROJECTION);
161  glPushMatrix();
162  glLoadIdentity();
[3364]163  /* set up an ortho screen */
164  glOrtho(0, screenWidth, 0, screenHeight, -1, 1); 
[3362]165  glMatrixMode(GL_MODELVIEW);
166  glLoadIdentity();
167  glPushMatrix();
[3367]168
[3362]169  glEnable(GL_BLEND);
[3367]170  glPushAttrib(GL_LIGHTING_BIT | GL_TRANSFORM_BIT);
171  glDisable(GL_LIGHTING);
[3362]172
173  glBegin(GL_QUADS);
[3367]174  glColor3f(0.96, 0.84, 0.34);
175  glVertex2i(barX, barY);
[3368]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);
[3367]185  glVertex2i(barX + barWidth, barY);
186  glVertex2i(barX + barWidth, barY + barHeight);
187  glVertex2i(barX, barY + barHeight);
188  glColor3f(1.0, 1.0, 1.0);
[3362]189  glEnd();
190
[3368]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
[3536]211  backMat->select();
[3364]212  glBegin(GL_QUADS);
[3367]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);
[3364]217  glEnd();
[3367]218  glDisable(GL_TEXTURE_2D);
[3364]219
[3362]220  glDisable(GL_BLEND);
221  glPopMatrix();
222  glMatrixMode(GL_PROJECTION);
223  glPopMatrix();
224  glPopAttrib();
225
[3358]226  SDL_GL_SwapBuffers();                   
227}
[3363]228 
[3358]229
[3357]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{}
[3363]254
255
256/**
257   \brief set the maximum of countable steps
258   \param maximum of steps
259*/
[3368]260void GLMenuImageScreen::setMaximum(int maxValue)
[3363]261{
[3368]262  this->maxValue = maxValue;
[3363]263}
264
265
266/**
267   \brief gets the maximum of countable steps
268*/
269int GLMenuImageScreen::getMaximum()
270{
[3368]271  return this->maxValue;
[3363]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++;
[3368]303  this->draw();
[3363]304}
Note: See TracBrowser for help on using the repository browser.