Changeset 4099 in orxonox.OLD for orxonox/trunk/src/glmenu
- Timestamp:
- May 7, 2005, 2:55:23 AM (20 years ago)
- Location:
- orxonox/trunk/src/glmenu
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/glmenu/glmenu_imagescreen.cc
r3729 r4099 20 20 21 21 #include "stdincl.h" 22 #include "graphics_engine.h" 22 23 #include "material.h" 23 24 24 25 using 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 35 26 /** 36 27 \brief standard constructor … … 44 35 } 45 36 46 47 37 /** 48 38 \brief standard deconstructor … … 51 41 GLMenuImageScreen::~GLMenuImageScreen() 52 42 { 53 if (this->backMat)54 delete this->backMat;43 delete this->backMat; 44 delete barMat; 55 45 } 56 46 … … 60 50 void GLMenuImageScreen::init () 61 51 { 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 52 // Select Our VU Meter Background Texture 83 53 this->backMat = new Material("load_screen"); 84 this->ba ckMat->setDiffuseMap("pictures/load_screen.jpg");54 this->barMat = new Material("bar"); 85 55 this->maxValue = 10; 86 56 this->currentValue = 0; 87 57 this->setPosition(0,0); 58 this->setScale(1,1); 59 this->setBarPosScale( .55, .7, .3, .15); 88 60 // End of Background image code. 89 61 } 90 91 92 /**93 \brief function to innit screen with all attributes set94 \param name of the background-image file95 \param height of the ImageScreen96 \param width of the Image Screen97 \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 screenbuffer110 */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 211 62 212 63 /** … … 214 65 \param file name of the backgroun-image 215 66 */ 216 void GLMenuImageScreen::setBackImageName (char* backImageName) 217 {} 67 void GLMenuImageScreen::setBackgroundImage (const char* backImageName) 68 { 69 this->backMat->setDiffuseMap(backImageName); 70 } 218 71 219 72 220 73 /** 221 74 \brief sets position of the ImageScreen 222 \param x offset from (0, 0)223 \param y offset from (0, 0)75 \param x offset from the top left corner in percent(0-1) of the screensize 76 \param y offset from the top left corner in percent(0-1) of the screensize 224 77 */ 225 78 void GLMenuImageScreen::setPosition(float offsetX, float offsetY) 226 {} 79 { 80 this->offsetX = offsetX; 81 this->offsetY = offsetY; 82 } 227 83 228 84 229 85 /* 230 86 \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 {} 87 \param scaleX the scaleing of the image into the x-direction (in percent (0-1)) 88 \param scaleY the scaleing of the image into the y-direction (in percent (0-1)) 89 */ 90 void GLMenuImageScreen::setScale(float scaleX, float scaleY) 91 { 92 this->scaleX = scaleX; 93 this->scaleY = scaleY; 94 } 95 96 /** 97 \param barImage An image for the Bar 98 */ 99 void GLMenuImageScreen::setBarImage(const char* barImage) 100 { 101 this->barMat->setDiffuseMap(barImage); 102 } 103 104 /** 105 \brief sets the Position and the Size of the bar 106 \param barX The Position in the x-direction in percent of the screen (0-1) 107 \param barY The Position in the y-direction in percent of the screen (0-1) 108 \param barW The Size in the x-direction in percent of the screen (0-1) 109 \param barH The Size in the y-direction in percent of the screen (0-1) 110 */ 111 void GLMenuImageScreen::setBarPosScale(float barX, float barY, float barW, float barH) 112 { 113 this->barX = barX; 114 this->barY = barY; 115 this->barW = barW; 116 this->barH = barH; 117 } 236 118 237 119 … … 285 167 this->draw(); 286 168 } 169 170 171 172 /** 173 \brief draws the ImageScreen to the screenbuffer 174 */ 175 void GLMenuImageScreen::draw () 176 { 177 glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); 178 179 PRINTF(4)("GLMenuImagEscreen::draw() - drawing step %i/%i\n", 180 this->currentValue, this->maxValue); 181 182 /* screen size */ 183 int screenWidth = GraphicsEngine::getInstance()->getResolutionX(); 184 int screenHeight = GraphicsEngine::getInstance()->getResolutionY(); 185 186 int imageWidth = (int)(screenWidth * this->scaleX); 187 int imageHeight = (int)(screenHeight * this->scaleY); 188 189 int offsetX = (int)(this->offsetX * screenWidth); 190 int offsetY = (int)(this->offsetY * screenHeight); 191 192 /* loadbar pos */ 193 int barX = (int)(this->barX *screenWidth); 194 int barY = (int)(this->barY *screenHeight); 195 int barW = (int)(this->barW *screenWidth); 196 int barH = (int)(this->barH *screenHeight); 197 198 int val = (int)(((float)this->currentValue/(float)this->maxValue) 199 * this->barW * (float)screenWidth); 200 if( val > barW) 201 val = barW; 202 203 printf(":::::::::::::::::::::%d %d %d %d %d\n", screenHeight, barY, barW, barH, val); 204 205 GraphicsEngine::enter2DMode(); 206 207 /* draw the BackGround */ 208 backMat->select(); 209 glBegin(GL_TRIANGLE_STRIP); 210 glTexCoord2i(0, 0); glVertex2i(offsetX, offsetY + imageHeight); 211 glTexCoord2i(1, 0); glVertex2i(offsetX +imageWidth, offsetY + imageHeight); 212 glTexCoord2i(0, 1); glVertex2i(offsetX, offsetY); 213 glTexCoord2i(1, 1); glVertex2i(offsetX + imageWidth, offsetY); 214 glEnd(); 215 216 217 /* draw the progress bar */ 218 barMat->select(); 219 glBegin(GL_TRIANGLE_STRIP); 220 glColor3f(0.96, 0.84, 0.34); 221 glTexCoord2i(0, 0); glVertex2i(barX, barY + barH); 222 glTexCoord2i(1, 0); glVertex2i(barX + val, barY + barH); 223 glTexCoord2i(0, 1); glVertex2i(barX, barY); 224 glTexCoord2i(1, 1); glVertex2i(barX + val, barY); 225 glEnd(); 226 227 /* 228 glBegin(GL_QUADS); 229 glColor3f(0.0, 0.0, 0.0); 230 glVertex2i(barX, barY); 231 glVertex2i(barX + barWidth, barY); 232 glVertex2i(barX + barWidth, barY + barHeight); 233 glVertex2i(barX, barY + barHeight); 234 glColor3f(1.0, 1.0, 1.0); 235 glEnd(); 236 237 /* draw black border 238 glBegin(GL_QUADS); 239 glColor3f(0.0, 0.0, 0.0); 240 glVertex2i(barX-1, barY-1); 241 glVertex2i(barX + barWidth +1, barY-1); 242 glVertex2i(barX + barWidth+1, barY + barHeight+1); 243 glVertex2i(barX - 1, barY + barHeight +1); 244 glColor3f(1.0, 1.0, 1.0); 245 glEnd(); 246 247 /* draw white border / 248 glBegin(GL_QUADS); 249 glColor3f(1.0, 1.0, 1.0); 250 glVertex2i(barX-2, barY-2); 251 glVertex2i(barX + barWidth +2, barY-2); 252 glVertex2i(barX + barWidth+2, barY + barHeight+2); 253 glVertex2i(barX - 2, barY + barHeight +2); 254 glColor3f(1.0, 1.0, 1.0); 255 glEnd(); 256 */ 257 258 GraphicsEngine::leave2DMode(); 259 260 SDL_GL_SwapBuffers(); 261 } 262 263 -
orxonox/trunk/src/glmenu/glmenu_imagescreen.h
r3675 r4099 15 15 16 16 private: 17 GLMenuImageScreen ();18 17 19 18 public: 19 GLMenuImageScreen (); 20 20 virtual ~GLMenuImageScreen (); 21 22 static GLMenuImageScreen* getInstance();23 24 static GLMenuImageScreen* singletonRef;25 21 26 22 void init (); 27 void init (char* backImageName, float height, float width,28 float offsetX, float offsetY);29 23 30 24 void draw (); 31 25 32 void setBackImageName (char* backImageName); 33 void setPosition (float offsetX, float offsetY); 34 void setSize (float height, float width); 35 26 void setBackgroundImage(const char* backImageName); 27 void setPosition(float offsetX, float offsetY); 28 void setScale (float scaleX, float scaleY); 29 30 void setBarImage(const char* barImage); 31 void setBarPosScale(float barX, float barY, float barW, float barH); 32 36 33 void setMaximum (int maxValue); 37 34 int getMaximum (); … … 42 39 private: 43 40 char* backImageName; //!< the name of the file of the background image 44 float height, width;//!< hight and width of the image41 float scaleX, scaleY; //!< hight and width of the image 45 42 float offsetX, offsetY; //!< offset of the image from left and up 46 43 Material* backMat; //!< Background Material. 44 float barX, barY, barW, barH; //!< Position and Scale of the bar. 45 Material* barMat; //!< A Material for the Loading-Bar 47 46 48 47 /* progress bar values */
Note: See TracChangeset
for help on using the changeset viewer.