Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4139 in orxonox.OLD for orxonox/branches/md2_loader/src/glmenu


Ignore:
Timestamp:
May 10, 2005, 10:39:01 AM (19 years ago)
Author:
patrick
Message:

orxonox/branches/md2_loader: merged trunk into branche using: svn merge ../trunk/ md2_loader -r 4063:HEAD

Location:
orxonox/branches/md2_loader/src/glmenu
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/md2_loader/src/glmenu/glmenu_imagescreen.cc

    r3729 r4139  
    2020
    2121#include "stdincl.h"
     22#include "graphics_engine.h"
    2223#include "material.h"
    2324
     25CREATE_FACTORY(GLMenuImageScreen);
     26
     27
    2428using namespace std;
    25 
    26 GLMenuImageScreen* GLMenuImageScreen::singletonRef = 0;
    27 
    28 GLMenuImageScreen* GLMenuImageScreen::getInstance()
    29 {
    30   if(!singletonRef)
    31     singletonRef = new GLMenuImageScreen ();
    32   return singletonRef;
    33 }
    34 
    3529/**
    3630   \brief standard constructor
    37 
    38    \todo this constructor is not jet implemented - do it
    3931*/
    4032GLMenuImageScreen::GLMenuImageScreen ()
    4133{
    42    this->setClassName ("GLMenuImageScreen");
    4334   this->init();
    4435}
    4536
     37/**
     38   \param root The Element to load the GLMenu from
     39*/
     40GLMenuImageScreen::GLMenuImageScreen (TiXmlElement* root)
     41{
     42  this->init();
     43  this->load(root);
     44
     45}
     46
     47/**
     48   \brief Loads a GLMenu from an inputElement
     49   \param root The Element to load the GLMenu from
     50
     51   Tags are:
     52   \li BackgroundImage STRING: the background Image
     53   \li BarImage: STRING: the Image on the Bar
     54   \li BackgroundPS: FLOAT FLOAT FLOAT FLOAT: posX posY scaleX scaleY
     55   \li BarPS: FLOAT FLOAT FLOAT FLOAT: posX posY scaleX scaleY
     56   \li ElementCount: INT: how many elements will be loaded
     57*/
     58void GLMenuImageScreen::load(TiXmlElement* root)
     59{
     60  const char* string;
     61
     62  // Model Loading     
     63  string = grabParameter( root, "BackgroundImage");
     64  if( string != NULL)
     65    this->setBackgroundImage(string);
     66
     67  string = grabParameter(root, "BackgroundPS");
     68  if (string != NULL)
     69    {
     70      float f1, f2, f3, f4;
     71      sscanf (string, "%f %f %f %f", &f1, &f2, &f3, &f4);
     72      this->setPosition(f1,f2);
     73      this->setScale(f3,f4);
     74    }
     75
     76  string = grabParameter( root, "BarImage");
     77  if (string != NULL)
     78    this->setBarImage(string);
     79  string = grabParameter(root, "BarPS");
     80  if (string != NULL)
     81    {
     82      float f1, f2, f3, f4;
     83      sscanf (string, "%f %f %f %f", &f1, &f2, &f3, &f4);
     84      this->setBarPosScale(f1,f2,f3,f4);
     85    }
     86
     87  string = grabParameter( root, "ElementCount");
     88  if (string != NULL)
     89    this->setMaximum(atoi(string));
     90}
    4691
    4792/**
     
    5196GLMenuImageScreen::~GLMenuImageScreen()
    5297{
    53   if (this->backMat)
    54     delete this->backMat;
     98  delete this->backMat;
     99  delete this->barMat;
    55100}
    56101
     
    60105void GLMenuImageScreen::init ()
    61106{
    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  
     107  this->setClassName ("GLMenuImageScreen");
     108
    82109  // Select Our VU Meter Background Texture
    83110  this->backMat = new Material("load_screen");
    84   this->backMat->setDiffuseMap("pictures/load_screen.jpg");
     111  this->barMat = new Material("bar");
    85112  this->maxValue = 10;
    86113  this->currentValue = 0;
    87 
     114  this->setPosition(0,0);
     115  this->setScale(1,1);
     116  this->setBarPosScale( .6, .75, .3, .1);
    88117  // End of Background image code.
    89118}
    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 */
    103 void 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 */
    111 void GLMenuImageScreen::draw ()
    112 {
    113 
    114   glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    115 
    116   PRINTF(4)("GLMenuImagEscreen::draw() - drawing step %i/%i\n",
    117          this->currentValue, this->maxValue);
    118 
    119   /* screen size */
    120   int screenWidth = 640;
    121   int screenHeight = 480;
    122  
    123   /* set image size */
    124   int imageWidth = 640;
    125   int imageHeight = 480;
    126  
    127   /* start pos of image */
    128   int offsetX = (screenWidth - imageWidth)/2;
    129   int offsetY = (screenHeight - imageHeight)/2;
    130  
    131   /* loadbar pos */
    132   int barX = 390;
    133   int barY = 50;
    134   int barWidth = 230;
    135   int barHeight = 30;
    136  
    137   float val = ((float)this->currentValue/(float)this->maxValue) * barWidth;
    138   if( val > (float)barWidth)
    139     val = (float)barWidth;
    140 
    141   glMatrixMode(GL_PROJECTION);
    142   glPushMatrix();
    143   glLoadIdentity();
    144   /* set up an ortho screen */
    145   glOrtho(0, screenWidth, 0, screenHeight, -1, 1);
    146   glMatrixMode(GL_MODELVIEW);
    147   glLoadIdentity();
    148   glPushMatrix();
    149 
    150   glEnable(GL_BLEND);
    151   glPushAttrib(GL_LIGHTING_BIT | GL_TRANSFORM_BIT);
    152   glDisable(GL_LIGHTING);
    153 
    154   /* draw the progress bar */
    155   glBegin(GL_QUADS);
    156   glColor3f(0.96, 0.84, 0.34);
    157   glVertex2i(barX, barY);
    158   glVertex2i(barX + (int)val, barY);
    159   glVertex2i(barX + (int)val, barY + barHeight);
    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);
    167   glVertex2i(barX + barWidth, barY);
    168   glVertex2i(barX + barWidth, barY + barHeight);
    169   glVertex2i(barX, barY + barHeight);
    170   glColor3f(1.0, 1.0, 1.0);
    171   glEnd();
    172 
    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 
    193   backMat->select();
    194   glBegin(GL_QUADS);
    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);
    199   glEnd();
    200   glDisable(GL_TEXTURE_2D);
    201 
    202   glDisable(GL_BLEND);
    203   glPopMatrix();
    204   glMatrixMode(GL_PROJECTION);
    205   glPopMatrix();
    206   glPopAttrib();
    207 
    208   SDL_GL_SwapBuffers();             
    209 }
    210  
    211119
    212120/**
     
    214122    \param file name of the backgroun-image
    215123 */
    216 void GLMenuImageScreen::setBackImageName (char* backImageName)
    217 {}
     124void GLMenuImageScreen::setBackgroundImage (const char* backImageName)
     125{
     126  this->backMat->setDiffuseMap(backImageName);
     127}
    218128
    219129
    220130/**
    221131   \brief sets position of the ImageScreen
    222    \param x offset from (0, 0)
    223    \param y offset from (0, 0)
     132   \param x offset from the top left corner in percent(0-1) of the screensize
     133   \param y offset from the top left corner in percent(0-1) of the screensize
    224134*/
    225135void GLMenuImageScreen::setPosition(float offsetX, float offsetY)
    226 {}
     136{
     137  this->offsetX = offsetX;
     138  this->offsetY = offsetY;
     139}
    227140
    228141
    229142/*
    230143  \brief sets size of the ImageScreen
    231   \param height of the ImageScreen
    232   \param width of the Image Screen
    233 */
    234 void GLMenuImageScreen::setSize(float height, float width)
    235 {}
     144  \param scaleX the scaleing of the image into the x-direction (in percent (0-1))
     145  \param scaleY the scaleing of the image into the y-direction (in percent (0-1))
     146*/
     147void GLMenuImageScreen::setScale(float scaleX, float scaleY)
     148{
     149  this->scaleX = scaleX;
     150  this->scaleY = scaleY;
     151}
     152
     153/**
     154   \param barImage An image for the Bar
     155*/
     156void GLMenuImageScreen::setBarImage(const char* barImage)
     157{
     158  this->barMat->setDiffuseMap(barImage);
     159}
     160
     161/**
     162   \brief sets the Position and the Size of the bar
     163   \param barX The Position in the x-direction in percent of the screen (0-1)
     164   \param barY The Position in the y-direction in percent of the screen (0-1)
     165   \param barW The Size in the x-direction in percent of the screen (0-1)
     166   \param barH The Size in the y-direction in percent of the screen (0-1)
     167*/
     168void GLMenuImageScreen::setBarPosScale(float barX, float barY, float barW, float barH)
     169{
     170  this->barX = barX;
     171  this->barY = barY;
     172  this->barW = barW;
     173  this->barH = barH;
     174}
    236175
    237176
     
    285224  this->draw();
    286225}
     226
     227
     228
     229/**
     230   \brief draws the ImageScreen to the screenbuffer
     231*/
     232void GLMenuImageScreen::draw ()
     233{
     234  glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
     235
     236  PRINTF(4)("GLMenuImagEscreen::draw() - drawing step %i/%i\n",
     237            this->currentValue, this->maxValue);
     238
     239  /* screen size */
     240  int screenWidth = GraphicsEngine::getInstance()->getResolutionX();
     241  int screenHeight = GraphicsEngine::getInstance()->getResolutionY();
     242 
     243  int imageWidth = (int)(screenWidth * this->scaleX);
     244  int imageHeight = (int)(screenHeight * this->scaleY);
     245
     246  int offsetX = (int)(this->offsetX * screenWidth);
     247  int offsetY = (int)(this->offsetY * screenHeight);
     248
     249  /* loadbar pos */
     250  int barX = (int)(this->barX *screenWidth);
     251  int barY = (int)(this->barY *screenHeight);
     252  int barW = (int)(this->barW *screenWidth);
     253  int barH = (int)(this->barH *screenHeight);
     254 
     255  float val = (float)this->currentValue/(float)this->maxValue;
     256                 
     257  if( val > barW)
     258    val = barW;
     259
     260  GraphicsEngine::enter2DMode();
     261
     262  /* draw the BackGround */
     263  backMat->select();
     264  glBegin(GL_TRIANGLE_STRIP);
     265  glTexCoord2i(0, 0); glVertex2i(offsetX, offsetY + imageHeight);
     266  glTexCoord2i(1, 0); glVertex2i(offsetX +imageWidth, offsetY + imageHeight);
     267  glTexCoord2i(0, 1); glVertex2i(offsetX, offsetY);
     268  glTexCoord2i(1, 1); glVertex2i(offsetX + imageWidth, offsetY);
     269  glEnd();
     270 
     271  glDisable(GL_TEXTURE_2D);
     272  /* draw white border */
     273  glBegin(GL_LINE_LOOP);
     274  glColor3f(1.0, 1.0, 1.0);
     275  glVertex2i(barX - 2, barY - 2);
     276  glVertex2i(barX + barW + 2, barY - 2);
     277  glVertex2i(barX + barW + 2, barY + barH + 2);
     278  glVertex2i(barX - 2, barY + barH + 2);
     279  glColor3f(1.0, 1.0, 1.0);
     280  glEnd();
     281 
     282  /* draw the progress bar */
     283  barMat->select();
     284  glBegin(GL_TRIANGLE_STRIP);
     285  glTexCoord2f(0, 0); glVertex2i(barX, barY + barH);
     286  glTexCoord2f(val, 0); glVertex2i(barX + (int)(val * this->barW * (float)screenWidth), barY + barH);
     287  glTexCoord2f(0, 1); glVertex2i(barX, barY);
     288  glTexCoord2f(val, 1); glVertex2i(barX + (int)(val * this->barW * (float)screenWidth), barY);
     289  glEnd();
     290
     291  /*
     292    glBegin(GL_QUADS);
     293    glColor3f(0.0, 0.0, 0.0);
     294    glVertex2i(barX, barY);
     295    glVertex2i(barX + barWidth, barY);
     296    glVertex2i(barX + barWidth, barY + barHeight);
     297    glVertex2i(barX, barY + barHeight);
     298    glColor3f(1.0, 1.0, 1.0);
     299    glEnd();
     300   
     301    /* draw black border
     302    glBegin(GL_QUADS);
     303    glColor3f(0.0, 0.0, 0.0);
     304    glVertex2i(barX-1, barY-1);
     305    glVertex2i(barX + barWidth +1, barY-1);
     306    glVertex2i(barX + barWidth+1, barY + barHeight+1);
     307    glVertex2i(barX - 1, barY + barHeight +1);
     308    glColor3f(1.0, 1.0, 1.0);
     309    glEnd();
     310   
     311  */
     312
     313  GraphicsEngine::leave2DMode();
     314
     315  SDL_GL_SwapBuffers();             
     316}
     317 
     318
  • orxonox/branches/md2_loader/src/glmenu/glmenu_imagescreen.h

    r3675 r4139  
    1111
    1212class Material;
     13class TiXmlElement;
    1314
    1415class GLMenuImageScreen : public BaseObject {
    1516
    16  private:
     17 public:
    1718  GLMenuImageScreen ();
    18 
    19  public:
     19  GLMenuImageScreen (TiXmlElement* root);
     20  void load(TiXmlElement* root);
    2021  virtual ~GLMenuImageScreen ();
    21  
    22   static GLMenuImageScreen* getInstance();
    23 
    24   static GLMenuImageScreen* singletonRef;
    2522
    2623  void init ();
    27   void init (char* backImageName, float height, float width,
    28              float offsetX, float offsetY);
    2924
    3025  void draw ();
    3126 
    32   void setBackImageName (char* backImageName);
    33   void setPosition (float offsetX, float offsetY);
    34   void setSize (float height, float width);
    35  
     27  void setBackgroundImage(const char* backImageName);
     28  void setPosition(float offsetX, float offsetY);
     29  void setScale (float scaleX, float scaleY);
     30
     31  void setBarImage(const char* barImage);
     32  void setBarPosScale(float barX, float barY, float barW, float barH);
     33
    3634  void setMaximum (int maxValue);
    3735  int getMaximum ();
     
    4240 private:
    4341  char* backImageName;       //!< the name of the file of the background image
    44   float height, width;       //!< hight and width of the image
     42  float scaleX, scaleY;      //!< hight and width of the image
    4543  float offsetX, offsetY;    //!< offset of the image from left and up
    4644  Material* backMat;         //!< Background Material.
     45  float barX, barY, barW, barH; //!< Position and Scale of the bar.
     46  Material* barMat;          //!< A Material for the Loading-Bar
    4747
    4848  /* progress bar values */
Note: See TracChangeset for help on using the changeset viewer.