Changeset 5367 in orxonox.OLD for trunk/src/lib/graphics
- Timestamp:
- Oct 12, 2005, 11:07:22 PM (19 years ago)
- Location:
- trunk/src/lib/graphics/text_engine
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/text_engine/font.cc
r5357 r5367 106 106 if (this->glyphArray[i] != NULL) 107 107 { 108 if (this->glyphArray[i]->displayList != 0)109 glDeleteLists(this->glyphArray[i]->displayList, 1);110 108 delete this->glyphArray[i]; 111 109 } … … 204 202 { 205 203 float cx,cy; 206 Glyph* glyph;204 Glyph* tmpGlyph; 207 205 this->glyphArray = new Glyph*[FONT_HIGHEST_KNOWN_CHAR]; 208 206 for (int i = 0; i < FONT_HIGHEST_KNOWN_CHAR; i++) 209 207 { 210 glyph = this->glyphArray[i] = new Glyph; 211 glyph->displayList = glGenLists(1); 212 if (!glIsList(glyph->displayList)) 213 { 214 PRINTF(2)("Error creating glList for Font character %c\n", i); 215 this->glyphArray[i] = NULL; 216 delete glyph; 217 continue; 218 } 208 tmpGlyph = this->glyphArray[i] = new Glyph; 219 209 cx=(float)(i%16)/16.0f; // X Position Of Current Character 220 210 cy=(float)(i/16)/16.0f; // Y Position Of Current Character 221 glNewList(glyph->displayList, GL_COMPILE); // Start Building A List 222 glBegin(GL_QUADS); // Use A Quad For Each Character 223 glTexCoord2f(cx, cy+0.001f); // Texture Coord (Bottom Left) 224 glVertex2d(0,-16); // Vertex Coord (Bottom Left) 225 glTexCoord2f(cx+0.0625f, cy+0.001f); // Texture Coord (Bottom Right) 226 glVertex2i(16,-16); // Vertex Coord (Bottom Right) 227 glTexCoord2f(cx+0.0625f, cy+0.0625f); // Texture Coord (Top Right) 228 glVertex2i(16,0); // Vertex Coord (Top Right) 229 glTexCoord2f(cx, cy+0.0625f); // Texture Coord (Top Left) 230 glVertex2i(0,0); // Vertex Coord (Top Left) 231 glEnd(); // Done Building Our Quad (Character) 232 // glTranslated(12,0,0); // Move To The Right Of The Character 233 glEndList(); // Done Building The Display List 234 this->glyphArray[i]->width = 12; 211 212 tmpGlyph->texCoord[0] = cx; 213 tmpGlyph->texCoord[1] = cx+0.0625f; 214 tmpGlyph->texCoord[2] = cy+0.001f; 215 tmpGlyph->texCoord[3] = cy+0.0625f; 216 tmpGlyph->width = 16; 217 tmpGlyph->bearingX = 16; 218 tmpGlyph->bearingY = 16; 219 tmpGlyph->height = 16; 235 220 } 236 221 } … … 292 277 0xFF000000 293 278 #else 294 279 0xFF000000, 295 280 0x00FF0000, 296 281 0x0000FF00, … … 322 307 SDL_BlitSurface(glyphSurf, NULL, tmpSurf, &tmpRect); 323 308 SDL_FreeSurface(glyphSurf); 324 // Outputting Glyphs to BMP-files.325 /*326 char outname[512];327 if (i < 10)328 sprintf( outname, "%s-glyph-00%d.bmp", this->getName(), i );329 else if (i <100)330 sprintf( outname, "%s-glyph-0%d.bmp", this->getName(), i );331 else332 sprintf( outname, "%s-glyph-%d.bmp", this->getName(), i );333 SDL_SaveBMP(tmpSurf, outname);*/334 335 309 } 336 310 } … … 409 383 { 410 384 Glyph* rg = new Glyph; 411 rg->displayList = 0;412 385 rg->character = character; 413 386 if (likely (this->font!= NULL)) … … 485 458 if (tmpRect.y + maxLineHeight > tmpSurf->h) 486 459 { 487 PRINTF(1)("Protection, so font cannot write over the boundraries error (this should not heappen\n");460 PRINTF(1)("Protection, so font cannot write over the boundraries (!!this should not heappen!!)\n"); 488 461 break; 489 462 } … … 499 472 500 473 SDL_BlitSurface(glyphSurf, NULL, tmpSurf, &tmpRect); 501 TexCoord tmpTexCoord; 502 tmpTexCoord.minU = (float)tmpRect.x/(float)tmpSurf->w; 503 tmpTexCoord.maxU = (float)(tmpRect.x + tmpGlyph->advance)/(float)tmpSurf->w; 504 tmpTexCoord.minV = (float)(tmpRect.y)/(float)tmpSurf->w; 505 tmpTexCoord.maxV = (float)(tmpRect.y+tmpGlyph->height)/(float)tmpSurf->w; 506 tmpGlyph->displayList = glGenLists(1); 507 508 glNewList(tmpGlyph->displayList, GL_COMPILE); 509 glBegin(GL_QUADS); 510 glTexCoord2f(tmpTexCoord.minU, tmpTexCoord.minV); 511 glVertex2d(0, - tmpGlyph->bearingY); 512 glTexCoord2f(tmpTexCoord.minU, tmpTexCoord.maxV); 513 glVertex2d(0, tmpGlyph->height - tmpGlyph->bearingY); 514 glTexCoord2f(tmpTexCoord.maxU, tmpTexCoord.maxV); 515 glVertex2d(tmpGlyph->width, tmpGlyph->height - tmpGlyph->bearingY); 516 glTexCoord2f(tmpTexCoord.maxU, tmpTexCoord.minV); 517 glVertex2d(tmpGlyph->width, - tmpGlyph->bearingY); 518 glEnd(); 519 glEndList(); 474 tmpGlyph->texCoord[0] = (float)tmpRect.x/(float)tmpSurf->w; 475 tmpGlyph->texCoord[1] = (float)(tmpRect.x + tmpGlyph->advance)/(float)tmpSurf->w; 476 tmpGlyph->texCoord[2] = (float)(tmpRect.y)/(float)tmpSurf->w; 477 tmpGlyph->texCoord[3] = (float)(tmpRect.y+tmpGlyph->height)/(float)tmpSurf->w; 520 478 SDL_FreeSurface(glyphSurf); 521 479 -
trunk/src/lib/graphics/text_engine/font.h
r5355 r5367 47 47 int advance; //!< How big a Glyph would be in monospace-mode 48 48 49 // OpenGL-specific 50 // TexCoord texCoord; //!< A Texture Coordinate for this glyph. 51 GLuint displayList; //!< DiplayList to render this Glyph. 49 GLfloat texCoord[4]; //!< Texture coordinates: 0:left, 1:right, 2: top, 3: bottom. 52 50 }; 53 51 -
trunk/src/lib/graphics/text_engine/text.cc
r5362 r5367 70 70 this->blending = TEXT_DEFAULT_BLENDING; 71 71 this->color = TEXT_DEFAULT_COLOR; 72 this->size = TEXT_DEFAULT_SIZE; 72 73 this->setType(TEXT_RENDER_DYNAMIC); 73 74 … … 240 241 if (likely(tmpText != NULL)) 241 242 { 243 Glyph* tmpGlyph; 242 244 while (likely(*tmpText != '\0')) 243 245 { 244 if(likely( glyphArray[*tmpText]!= NULL))246 if(likely((tmpGlyph = glyphArray[*tmpText]) != NULL)) 245 247 { 246 glCallList(glyphArray[*tmpText]->displayList); 248 glBegin(GL_QUADS); 249 glTexCoord2f(tmpGlyph->texCoord[0], tmpGlyph->texCoord[2]); 250 glVertex2d(0, - tmpGlyph->bearingY); 251 glTexCoord2f(tmpGlyph->texCoord[0], tmpGlyph->texCoord[3]); 252 glVertex2d(0, tmpGlyph->height - tmpGlyph->bearingY); 253 glTexCoord2f(tmpGlyph->texCoord[1], tmpGlyph->texCoord[3]); 254 glVertex2d(tmpGlyph->width, tmpGlyph->height - tmpGlyph->bearingY); 255 glTexCoord2f(tmpGlyph->texCoord[1], tmpGlyph->texCoord[2]); 256 glVertex2d(tmpGlyph->width, - tmpGlyph->bearingY); 257 glEnd(); 258 glEndList(); 247 259 glTranslatef(glyphArray[*tmpText]->width, 0, 0); 248 260 } -
trunk/src/lib/graphics/text_engine/text.h
r5362 r5367 60 60 void setFont(const char* fontFile, unsigned int fontSize); 61 61 62 void setType(TEXT_RENDER_TYPE type);63 62 void setText(const char* text, bool isExtern = false); 63 64 64 /** @returns the String this Text displays */ 65 65 inline const char* getText() const { return (externText == NULL)?this->text:this->externText; }; … … 68 68 /** sets the Color of the Text to render (values in [0-1]) @param r red @param g green @param b blue */ 69 69 void setColor(float r, float g, float b) { this->color = Vector(r,g,b); }; 70 /** sets the Size of the Font */ 71 void setSize(float size) { this->size = size; }; 70 72 73 void setType(TEXT_RENDER_TYPE type); 71 74 void createTexture(); 72 75 … … 87 90 Vector color; //!< The color of the font. 88 91 float blending; //!< The blending intensity. 92 float size; //!< The size of the Font. 89 93 90 94 // placement in openGL
Note: See TracChangeset
for help on using the changeset viewer.