Changeset 4597 in orxonox.OLD for orxonox/trunk/src/lib/graphics
- Timestamp:
- Jun 11, 2005, 12:55:48 AM (19 years ago)
- Location:
- orxonox/trunk/src/lib/graphics
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/graphics/graphics_engine.cc
r4536 r4597 1 /* 1 /* 2 2 orxonox - the future of 3D-vertical-scrollers 3 3 … … 29 29 \todo this constructor is not jet implemented - do it 30 30 */ 31 GraphicsEngine::GraphicsEngine () 32 { 31 GraphicsEngine::GraphicsEngine () 32 { 33 this->setClassID(CL_GRAPHICS_ENGINE, "GraphicsEngine"); 34 this->setName("GraphicsEngine"); 33 35 this->bDisplayFPS = false; 34 36 this->minFPS = 9999; 35 37 this->maxFPS = 0; 36 this->setClassID(CL_GRAPHICS_ENGINE, "GraphicsEngine");37 38 38 39 this->fullscreen = false; … … 51 52 \brief destructs the graphicsEngine. 52 53 */ 53 GraphicsEngine::~GraphicsEngine () 54 GraphicsEngine::~GraphicsEngine () 54 55 { 55 56 // delete what has to be deleted here … … 79 80 if( videoInfo == NULL) 80 81 { 81 PRINTF(1)("Failed getting Video Info :%s\n", SDL_GetError()); 82 PRINTF(1)("Failed getting Video Info :%s\n", SDL_GetError()); 82 83 SDL_Quit (); 83 84 } 84 85 if( videoInfo->hw_available) 85 86 this->videoFlags |= SDL_HWSURFACE; 86 else 87 else 87 88 this->videoFlags |= SDL_SWSURFACE; 88 89 /* … … 93 94 // setting up the Resolution 94 95 this->setResolution(800, 600, 16); 95 96 96 97 // Set window labeling 97 98 SDL_WM_SetCaption ("Orxonox " PACKAGE_VERSION, "Orxonox " PACKAGE_VERSION); 98 99 99 100 // TO DO: Create a cool icon and use it here 100 101 char* loadPic = new char[strlen(ResourceManager::getInstance()->getDataDir())+ 100]; 101 102 sprintf(loadPic, "%s%s", ResourceManager::getInstance()->getDataDir(), "pictures/orxonox-icon32x32.bmp"); 102 SDL_WM_SetIcon(SDL_LoadBMP(loadPic), NULL); 103 SDL_WM_SetIcon(SDL_LoadBMP(loadPic), NULL); 103 104 delete loadPic; 104 105 // Enable default GL stuff … … 117 118 //SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); 118 119 //SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); 119 120 121 SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); 122 SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16); 123 SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, 0); 120 121 122 SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); 123 SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16); 124 SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, 0); 124 125 SDL_GL_SetAttribute( SDL_GL_ACCUM_RED_SIZE, 0); 125 126 SDL_GL_SetAttribute( SDL_GL_ACCUM_GREEN_SIZE, 0); … … 144 145 else 145 146 fullscreenFlag = 0; 146 147 147 148 printf ("ok\n"); 148 149 if((this->screen = SDL_SetVideoMode(this->resolutionX, this->resolutionY, this->bitsPerPixel, this->videoFlags | fullscreenFlag)) == NULL) … … 195 196 /** 196 197 \brief entering 2D Mode 197 198 198 199 this is a GL-Projection-mode, that is orthogonal, for placing the font in fron of everything else 199 200 */ … … 202 203 GraphicsEngine::storeMatrices(); 203 204 SDL_Surface *screen = SDL_GetVideoSurface(); 204 205 205 206 /* Note, there may be other things you need to change, 206 207 depending on how you have your OpenGL state set up. … … 215 216 glEnable(GL_BLEND); 216 217 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 217 218 218 219 glViewport(0, 0, screen->w, screen->h); 219 220 220 221 glMatrixMode(GL_PROJECTION); 221 222 glPushMatrix(); 222 223 glLoadIdentity(); 223 224 224 225 glOrtho(0.0, (GLdouble)screen->w, (GLdouble)screen->h, 0.0, 0.0, 1.0); 225 226 226 227 glMatrixMode(GL_MODELVIEW); 227 228 glPushMatrix(); 228 229 glLoadIdentity(); 229 230 230 231 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 231 232 } … … 238 239 glMatrixMode(GL_MODELVIEW); 239 240 glPopMatrix(); 240 241 241 242 glMatrixMode(GL_PROJECTION); 242 243 glPopMatrix(); 243 244 244 245 glPopAttrib(); 245 246 } 246 247 247 248 /** 248 \brief stores the GL_matrices 249 \brief stores the GL_matrices 249 250 */ 250 251 void GraphicsEngine::storeMatrices(void) … … 271 272 /* Get available fullscreen/hardware modes */ 272 273 this->videoModes=SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_HWSURFACE); 273 274 274 275 /* Check is there are any modes available */ 275 276 if(this->videoModes == (SDL_Rect **)0){ … … 277 278 exit(-1); 278 279 } 279 280 280 281 /* Check if our resolution is restricted */ 281 282 if(this->videoModes == (SDL_Rect **)-1){ … … 301 302 if( unlikely(this->currentFPS > this->maxFPS)) this->maxFPS = this->currentFPS; 302 303 if( unlikely(this->currentFPS < this->minFPS)) this->minFPS = this->currentFPS; 303 304 304 305 #ifndef NO_TEXT 305 306 char tmpChar1[20]; … … 315 316 } 316 317 } 317 318 318 319 /** 319 320 \brief displays the Frames per second … … 335 336 this->geTextMinFPS = TextEngine::getInstance()->createText("fonts/druid.ttf", 35, TEXT_DYNAMIC, 0, 255, 0); 336 337 this->geTextMinFPS->setAlignment(TEXT_ALIGN_LEFT); 337 this->geTextMinFPS->setPosition(5, 560); 338 this->geTextMinFPS->setPosition(5, 560); 338 339 #endif /* NO_TEXT */ 339 340 } … … 341 342 } 342 343 343 344 -
orxonox/trunk/src/lib/graphics/light.cc
r4519 r4597 1 1 2 2 3 /* 3 /* 4 4 orxonox - the future of 3D-vertical-scrollers 5 5 … … 36 36 { 37 37 this->setClassID(CL_LIGHT, "Light"); 38 char tmpName[ 7];39 sprintf(tmpName, "Light %d", lightNumber);38 char tmpName[10]; 39 sprintf(tmpName, "Light[%d]", lightNumber); 40 40 this->setName(tmpName); 41 41 … … 43 43 // enable The light 44 44 glEnable(lightsV[lightNumber]); // postSpawn 45 45 46 46 // set values (defaults) 47 47 this->lightNumber = lightNumber; … … 179 179 /** 180 180 \brief draws this Light. Being a World-entity the possibility to do this lies at hand. 181 */ 181 */ 182 182 void Light::draw() 183 183 { … … 195 195 PRINT(0)(":: %d :: -- reference %p\n", this->lightNumber, this); 196 196 PRINT(0)(" GL-state: "); 197 GLboolean param; 197 GLboolean param; 198 198 glGetBooleanv(lightsV[this->lightNumber], ¶m); 199 199 if (param) … … 201 201 else 202 202 PRINT(0)("OFF\n"); 203 203 204 204 PRINT(0)(" Position: %f/%f/%f\n", this->lightPosition[0], this->lightPosition[1], this->lightPosition[2]); 205 205 PRINT(0)(" DiffuseColor: %f/%f/%f\n", this->diffuseColor[0], this->diffuseColor[1], this->diffuseColor[2]); … … 215 215 \brief standard constructor for a Light 216 216 */ 217 LightManager::LightManager () 217 LightManager::LightManager () 218 218 { 219 219 this->setClassID(CL_LIGHT_MANAGER, "LightManager"); … … 229 229 /** 230 230 \brief standard deconstructor 231 231 232 232 first disables Lighting 233 233 … … 235 235 and in the end sets the singleton Reference to zero. 236 236 */ 237 LightManager::~LightManager () 237 LightManager::~LightManager () 238 238 { 239 239 glDisable(GL_LIGHTING); 240 240 241 241 // this will be done either by worldEntity, or by pNode as each light is one of them 242 242 // for (int i = 0; i < NUMBEROFLIGHTS; i++) … … 270 270 for (int i = 0; i < NUMBEROFLIGHTS; i++) 271 271 if (!this->lights[i]) 272 return addLight(i); 272 return addLight(i); 273 273 PRINTF(1)("no more light slots availiable. All %d already taken\n", NUMBEROFLIGHTS); 274 274 return -1; … … 302 302 { 303 303 if (!this->currentLight) 304 { 304 { 305 305 PRINTF(2)("no Light defined yet. Please define at least one light first befor editing.\n"); 306 306 return; … … 316 316 { 317 317 if (!this->currentLight) 318 { 318 { 319 319 PRINTF(1)("no Light defined yet. So you cannot delete any Light right now.\n"); 320 320 return; … … 392 392 { 393 393 if (!this->currentLight) 394 { 394 { 395 395 PRINTF(2)("no Light defined yet. Please define at least one light first befor editing.\n"); 396 396 return; … … 409 409 { 410 410 if (!this->currentLight) 411 { 411 { 412 412 PRINTF(2)("no Light defined yet. Please define at least one light first befor editing.\n"); 413 413 return; … … 426 426 { 427 427 if (!this->currentLight) 428 { 428 { 429 429 PRINTF(2)("no Light defined yet. Please define at least one light first befor editing.\n"); 430 430 return; … … 443 443 { 444 444 if (!this->currentLight) 445 { 445 { 446 446 PRINTF(2)("no Light defined yet. Please define at least one light first befor editing.\n"); 447 447 return; … … 458 458 { 459 459 if (!this->currentLight) 460 { 460 { 461 461 PRINTF(2)("no Light defined yet. Please define at least one light first befor editing.\n"); 462 462 return; … … 473 473 { 474 474 if (!this->currentLight) 475 { 475 { 476 476 PRINTF(2)("no Light defined yet. Please define at least one light first befor editing.\n"); 477 477 return; … … 488 488 { 489 489 if (!this->currentLight) 490 { 490 { 491 491 PRINTF(2)("no Light defined yet\n"); 492 492 return Vector(.0, .0, .0); … … 498 498 499 499 /** 500 \returns the Position of Light 500 \returns the Position of Light 501 501 \param lightNumber lightnumber 502 502 */ … … 539 539 if (this->lights[i]) 540 540 { 541 541 this->lights[i]->debug(); 542 542 } 543 543 PRINT(0)("--------------------------------\n"); -
orxonox/trunk/src/lib/graphics/text_engine.cc
r4537 r4597 1 /* 1 /* 2 2 orxonox - the future of 3D-vertical-scrollers 3 3 … … 16 16 17 17 !! IMPORTANT !! When using ttf fonts clear the license issues prior to 18 adding them to orxonox. This is really important, because we do not 18 adding them to orxonox. This is really important, because we do not 19 19 want to offend anyone. 20 20 */ … … 46 46 \param type The renderType to display this font in 47 47 48 this constructor is private, because the user should initialize 48 this constructor is private, because the user should initialize 49 49 a text with the TextEngine. 50 50 */ … … 68 68 /** 69 69 \brief deletes a Text out of memory 70 70 71 71 This also ereases the text from the textList of the TextEngine 72 72 */ … … 117 117 char* tmpText = this->text; 118 118 while (*tmpText != '\0') 119 120 121 122 123 124 125 119 { 120 if(glyphArray[*tmpText]) 121 { 122 width += glyphArray[*tmpText]->width; 123 } 124 tmpText++; 125 } 126 126 this->posSize.w = width; 127 127 } … … 174 174 if (likely(this->font != NULL)) 175 175 tmpSurf = TTF_RenderText_Blended(this->font->font, 176 177 176 this->text, 177 this->color); 178 178 if (tmpSurf) 179 179 this->texture = loadTexture(tmpSurf, &this->texCoord); … … 208 208 pos.z = tmp[2]; 209 209 } 210 else 210 else 211 211 { 212 212 pos.x = this->posSize.x; … … 232 232 glEnable(GL_TEXTURE_2D); 233 233 glBegin(GL_QUADS); 234 234 235 235 glTexCoord2f(this->texCoord.minU, this->texCoord.minV); 236 236 glVertex2f(pos.x, pos.y ); 237 237 238 238 glTexCoord2f(this->texCoord.maxU, this->texCoord.minV); 239 239 glVertex2f(pos.x + this->posSize.w, pos.y ); 240 240 241 241 glTexCoord2f(this->texCoord.maxU, this->texCoord.maxV); 242 242 glVertex2f(pos.x + this->posSize.w, pos.y + this->posSize.h); 243 243 244 244 glTexCoord2f(this->texCoord.minU, this->texCoord.maxV); 245 245 glVertex2f(pos.x, pos.y + this->posSize.h); 246 246 247 247 glEnd(); 248 248 } … … 257 257 char* tmpText = this->text; 258 258 while (*tmpText != '\0') 259 260 261 262 263 264 265 266 259 { 260 if(glyphArray[*tmpText]) 261 { 262 glCallList(glyphArray[*tmpText]->displayList); 263 glTranslatef(glyphArray[*tmpText]->width, 0, 0); 264 } 265 tmpText++; 266 } 267 267 } 268 268 glPopMatrix(); … … 299 299 Uint32 saved_flags; 300 300 Uint8 saved_alpha; 301 301 302 302 /* Use the surface width and height expanded to powers of 2 */ 303 303 w = powerOfTwo(surface->w); … … 311 311 } 312 312 image = SDL_CreateRGBSurface(SDL_SWSURFACE, 313 314 313 w, h, 314 32, 315 315 #if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */ 316 0x000000FF, 317 0x0000FF00, 318 0x00FF0000, 319 316 0x000000FF, 317 0x0000FF00, 318 0x00FF0000, 319 0xFF000000 320 320 #else 321 322 0x00FF0000, 323 0x0000FF00, 324 321 0xFF000000, 322 0x00FF0000, 323 0x0000FF00, 324 0x000000FF 325 325 #endif 326 326 ); 327 327 if ( image == NULL ) { 328 328 return 0; 329 329 } 330 330 331 331 /* Save the alpha blending attributes */ 332 332 saved_flags = surface->flags&(SDL_SRCALPHA|SDL_RLEACCELOK); … … 335 335 SDL_SetAlpha(surface, 0, 0); 336 336 } 337 337 338 338 /* Copy the surface into the GL texture image */ 339 339 area.x = 0; … … 342 342 area.h = surface->h; 343 343 SDL_BlitSurface(surface, &area, image, &area); 344 344 345 345 /* Restore the alpha blending attributes */ 346 346 if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) { 347 347 SDL_SetAlpha(surface, saved_flags, saved_alpha); 348 348 } 349 349 350 350 /* Create an OpenGL texture for the image */ 351 351 glGenTextures(1, &texture); … … 354 354 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 355 355 glTexImage2D(GL_TEXTURE_2D, 356 357 358 359 360 361 362 356 0, 357 GL_RGBA, 358 w, h, 359 0, 360 GL_RGBA, 361 GL_UNSIGNED_BYTE, 362 image->pixels); 363 363 SDL_FreeSurface(image); /* No longer needed */ 364 364 365 365 return texture; 366 366 } 367 367 368 368 /** 369 \brief Quick utility function for texture creation 369 \brief Quick utility function for texture creation 370 370 \param input an integer 371 371 \returns the next bigger 2^n-integer than input … … 374 374 { 375 375 int value = 1; 376 376 377 377 while ( value < input ) { 378 378 value <<= 1; … … 395 395 Font::Font(const char* fontFile, unsigned int fontSize, Uint8 r, Uint8 g, Uint8 b) 396 396 { 397 this->setClassID(CL_FONT, "Font"); 397 398 // setting default values. 398 399 this->font = NULL; 399 400 this->fontFile = NULL; 400 401 this->glyphArray = NULL; 401 this->fastTextureID = 0; 402 402 this->fastTextureID = 0; 403 403 404 this->setSize(fontSize); 404 405 … … 423 424 { 424 425 for (int i = 0; i < FONT_HIGHEST_KNOWN_CHAR; i++) 425 426 delete this->glyphArray[i]; 426 427 delete []this->glyphArray; 427 428 } … … 441 442 if (!this->fontFile) 442 443 { 444 this->setName(fontFile); 443 445 this->fontFile = new char[strlen(fontFile)+1]; 444 446 strcpy(this->fontFile, fontFile); 445 447 446 448 this->font = TTF_OpenFont(this->fontFile, this->fontSize); 447 449 if(!this->font) 448 449 450 451 450 { 451 PRINTF(1)("TTF_OpenFont: %s\n", TTF_GetError()); 452 return false; 453 } 452 454 else 453 455 return true; 454 456 } 455 457 else … … 468 470 { 469 471 this->renderStyle = TTF_STYLE_NORMAL; 470 472 471 473 for (int i = 0; i < strlen(renderStyle); i++) 472 if (strncmp(renderStyle+i, "b", 1) == 0) 474 if (strncmp(renderStyle+i, "b", 1) == 0) 473 475 this->renderStyle |= TTF_STYLE_BOLD; 474 476 else if (strncmp(renderStyle+i, "i", 1) == 0) 475 477 this->renderStyle |= TTF_STYLE_ITALIC; 476 else if (strncmp(renderStyle+i, "u", 1) == 0) 478 else if (strncmp(renderStyle+i, "u", 1) == 0) 477 479 this->renderStyle |= TTF_STYLE_UNDERLINE; 478 480 … … 547 549 and MUST be deleted by the user.. 548 550 549 This only works for horizontal fonts. see 551 This only works for horizontal fonts. see 550 552 http://freetype.sourceforge.net/freetype2/docs/tutorial/step2.html 551 553 for more info about vertical Fonts … … 557 559 if (likely (this->font!= NULL)) 558 560 TTF_GlyphMetrics(this->font, rg->character, 559 560 561 561 &rg->minX, &rg->maxX, 562 &rg->minY, &rg->maxY, 563 &rg->advance); 562 564 rg->height = rg->maxY - rg->minY; 563 565 rg->width = rg->maxX - rg->minX; … … 569 571 GLuint Font::createFastTexture(void) 570 572 { 571 /* interesting GLYPHS: 573 /* interesting GLYPHS: 572 574 * 32: space 573 575 * 33-47: Special Characters. … … 589 591 SDL_Rect tmpRect; // this represents a Rectangle for blitting. 590 592 SDL_Surface* tmpSurf = SDL_CreateRGBSurface(SDL_SWSURFACE, 591 592 593 rectSize, rectSize, 594 32, 593 595 #if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */ 594 0x000000FF, 595 0x0000FF00, 596 0x00FF0000, 597 596 0x000000FF, 597 0x0000FF00, 598 0x00FF0000, 599 0xFF000000 598 600 #else 599 600 0x00FF0000, 601 0x0000FF00, 602 601 0xFF000000, 602 0x00FF0000, 603 0x0000FF00, 604 0x000000FF 603 605 #endif 604 606 ); 605 607 tmpRect.x = 0; tmpRect.y = 0; tmpRect.w = tmpSurf->w; tmpRect.h = tmpSurf->h; 606 608 SDL_SetClipRect(tmpSurf, &tmpRect); … … 614 616 615 617 if (tmpGlyph = this->glyphArray[i]) 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 618 { 619 if (tmpGlyph->height > maxLineHeight) 620 maxLineHeight = tmpGlyph->height; 621 622 if (tmpRect.x+tmpGlyph->width > tmpSurf->w) 623 { 624 tmpRect.x = 0; 625 tmpRect.y = tmpRect.y + maxLineHeight + 1; 626 maxLineHeight = 0; 627 } 628 if (tmpRect.y + maxLineHeight > tmpSurf->h) 629 { 630 PRINTF(1)("Protection, so font cannot write over the boundraries error (this should not heappen\n"); 631 break; 632 } 633 // reading in the new Glyph 634 if (likely(this->font != NULL)) 635 glyphSurf = TTF_RenderGlyph_Blended(this->font, i, this->fastColor); 636 if( glyphSurf != NULL ) 637 { 638 639 SDL_SetAlpha(glyphSurf, 0, 0); 640 641 SDL_BlitSurface(glyphSurf, NULL, tmpSurf, &tmpRect); 642 TexCoord tmpTexCoord; 643 tmpTexCoord.minU = (float)tmpRect.x/(float)tmpSurf->w; 644 tmpTexCoord.maxU = (float)(tmpRect.x+tmpGlyph->width)/(float)tmpSurf->w; 645 tmpTexCoord.minV = (float)tmpRect.y/(float)tmpSurf->w; 646 tmpTexCoord.maxV = (float)(tmpRect.y+tmpGlyph->height)/(float)tmpSurf->w; 647 tmpGlyph->displayList = glGenLists(1); 648 649 glNewList(tmpGlyph->displayList, GL_COMPILE); 650 glBegin(GL_QUADS); 651 glTexCoord2f(tmpTexCoord.minU, tmpTexCoord.minV); 652 glVertex2d(0, 0); 653 glTexCoord2f(tmpTexCoord.minU, tmpTexCoord.maxV); 654 glVertex2d(0, tmpGlyph->height); 655 glTexCoord2f(tmpTexCoord.maxU, tmpTexCoord.maxV); 656 glVertex2d(tmpGlyph->width, tmpGlyph->height); 657 glTexCoord2f(tmpTexCoord.maxU, tmpTexCoord.minV); 658 glVertex2d(tmpGlyph->width, 0); 659 glEnd(); 660 glEndList(); 661 SDL_FreeSurface(glyphSurf); 662 663 tmpRect.x += tmpGlyph->width + 1; 664 665 // Outputting Glyphs to BMP-files. 666 /* 667 char outname[64]; 668 if (i < 10) 669 sprintf( outname, "glyph-00%d.bmp", i ); 670 else if (i <100) 671 sprintf( outname, "glyph-0%d.bmp", i ); 672 else 673 sprintf( outname, "glyph-%d.bmp", i ); 674 SDL_SaveBMP(tmpSurf, outname); 675 */ 676 } 677 } 676 678 } 677 679 … … 682 684 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 683 685 glTexImage2D(GL_TEXTURE_2D, 684 685 686 687 688 689 690 686 0, 687 GL_RGBA, 688 tmpSurf->w, tmpSurf->h, 689 0, 690 GL_RGBA, 691 GL_UNSIGNED_BYTE, 692 tmpSurf->pixels); 691 693 SDL_FreeSurface(tmpSurf); 692 694 return texture; … … 707 709 this->glyphArray = new Glyph*[FONT_HIGHEST_KNOWN_CHAR]; 708 710 for (int i = 0; i < FONT_HIGHEST_KNOWN_CHAR; i++) 709 710 } 711 711 this->glyphArray[i] = NULL; 712 } 713 712 714 Uint16 lastGlyph = from + count; 713 715 714 716 for (int i = from; i <= lastGlyph; i++) 715 717 { … … 723 725 \returns the optimal size to use as the texture size 724 726 725 \todo: this algorithm can be a lot more faster, althought it does 727 \todo: this algorithm can be a lot more faster, althought it does 726 728 not really matter within the init-context, and 128 glyphs. 727 729 728 This function searches for a 2^n sizes texture-size, this is for 730 This function searches for a 2^n sizes texture-size, this is for 729 731 openGL-version < 1.2 compatibility ( and because it is realy easy like this :)) 730 732 */ … … 743 745 maxLineHeight = 0; 744 746 for (i = 0; i < FONT_HIGHEST_KNOWN_CHAR; i++) 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 747 { 748 if(tmpGlyph = this->glyphArray[i]) 749 { 750 // getting the height of the highest Glyph in the Line. 751 if (tmpGlyph->height > maxLineHeight) 752 maxLineHeight = tmpGlyph->height; 753 754 if (x + tmpGlyph->width > size) 755 { 756 x = 0; 757 y = y + maxLineHeight; 758 maxLineHeight = 0; 759 } 760 if (y + maxLineHeight + 1 > size) 761 break; 762 x += tmpGlyph->width + 1; 763 764 } 765 } 764 766 if (i == FONT_HIGHEST_KNOWN_CHAR) 765 767 sizeOK = true; 766 768 else 767 769 size *= 2; 768 770 } 769 771 return size; … … 801 803 \brief standard constructor 802 804 */ 803 TextEngine::TextEngine () 805 TextEngine::TextEngine () 804 806 { 805 807 this->setClassID(CL_TEXT_ENGINE, "TextEngine"); 808 this->setName("TextEngine"); 806 809 this->enableFonts(); 807 810 … … 818 821 819 822 */ 820 TextEngine::~TextEngine () 823 TextEngine::~TextEngine () 821 824 { 822 825 this->disableFonts(); 823 826 824 827 delete this->textList; 825 828 … … 835 838 { 836 839 if(TTF_Init()==-1) 837 840 PRINTF(1)("TTF_Init: %s\n", TTF_GetError()); 838 841 839 842 TextEngine::checkVersion(); … … 932 935 /** 933 936 \brief outputs some nice Debug information 934 937 935 938 \todo there should also be something outputted about Font 936 939 */ … … 941 944 PRINT(0)("+-------------------------------+\n"); 942 945 PRINT(0)("Reference: %p; Text Counts: %d\n", this, this->textList->getSize()); 943 946 944 947 tIterator<Text>* textIterator = textList->getIterator(); 945 948 Text* text = textIterator->nextElement(); … … 973 976 else 974 977 { 975 PRINTF(2)("compiled with SDL_ttf version: %d.%d.%d\n", 976 977 978 979 980 PRINTF(2)("running with SDL_ttf version: %d.%d.%d\n", 981 982 983 978 PRINTF(2)("compiled with SDL_ttf version: %d.%d.%d\n", 979 compile_version.major, 980 compile_version.minor, 981 compile_version.patch); 982 983 PRINTF(2)("running with SDL_ttf version: %d.%d.%d\n", 984 link_version.major, 985 link_version.minor, 986 link_version.patch); 984 987 return false; 985 988 } -
orxonox/trunk/src/lib/graphics/text_engine.h
r4536 r4597 1 /*! 1 /*! 2 2 \file text_engine.h 3 3 \brief Definition of textEngine, the Font and the Text … … 30 30 31 31 //! An enumerator for the text alignment. 32 enum TEXT_ALIGNMENT { TEXT_ALIGN_LEFT, 33 TEXT_ALIGN_RIGHT, 34 TEXT_ALIGN_CENTER, 35 TEXT_ALIGN_SCREEN_CENTER }; 32 enum TEXT_ALIGNMENT 33 { 34 TEXT_ALIGN_LEFT, 35 TEXT_ALIGN_RIGHT, 36 TEXT_ALIGN_CENTER, 37 TEXT_ALIGN_SCREEN_CENTER 38 }; 36 39 37 40 /* some default values */ 38 41 #define FONT_DEFAULT_SIZE 50 //!< default size of the Text 39 #define FONT_DEFAULT_TEXT 42 #define FONT_DEFAULT_TEXT "orxonox 1234567890" //!< default text to display 40 43 #define FONT_DEFAULT_COLOR_R 255 //!< default red part (color) of the text 41 44 #define FONT_DEFAULT_COLOR_G 255 //!< default red green (color) of the text … … 86 89 int bearingY; //!< How much is above the Origin 87 90 int advance; //!< How big a Glyph would be in monospace-mode 88 91 89 92 // OpenGL-specific 90 93 // TexCoord texCoord; //!< A Texture Coordinate for this glyph. … … 117 120 118 121 void draw(void) const; 119 122 120 123 void debug(void) const; 121 124 122 125 private: 123 126 Text(Font* font, int type = TEXT_DYNAMIC); 124 127 125 128 static GLuint loadTexture(SDL_Surface* surface, TexCoord* texCoord); 126 129 static int powerOfTwo(int input); … … 139 142 TexCoord texCoord; //!< Texture-coordinates \todo fix this to have a struct 140 143 SDL_Rect posSize; //!< An SDL-Rectangle representing the position and size of the Text on the screen. 141 144 142 145 PNode* bindNode; //!< A node the Text is bind to. (if NULL thr node will not be bound to anything.) 143 146 }; … … 147 150 //////////// 148 151 //! A class to handle a Font of a certain ttf-File, Size and Color. 149 class Font 152 class Font : public BaseObject 150 153 { 151 154 friend class Text; … … 170 173 /** \returns the texture to the fast-texture */ 171 174 inline GLuint getFastTextureID(void) const {return fastTextureID;} 172 175 173 176 private: 174 177 int getMaxHeight(void); … … 193 196 unsigned int fontSize; //!< The size of the font in pixels. each Font has one size. 194 197 int renderStyle; //!< The Renderstyle 195 198 196 199 Glyph** glyphArray; //!< An Array of all the Glyphs stored in the Array of Glyphs. 197 200 GLuint fastTextureID; //!< The fast textureID. … … 205 208 /////////////////// 206 209 //! A singleton Class that operates as a Handler for generating and rendering Text in 2D 207 class TextEngine : public BaseObject 210 class TextEngine : public BaseObject 208 211 { 209 212 public: … … 213 216 214 217 Text* createText(const char* fontFile, 215 216 217 218 219 220 218 unsigned int fontSize = FONT_DEFAULT_SIZE, 219 int textType = TEXT_DYNAMIC, 220 Uint8 r = FONT_DEFAULT_COLOR_R, 221 Uint8 g = FONT_DEFAULT_COLOR_G, 222 Uint8 b = FONT_DEFAULT_COLOR_B); 223 221 224 void deleteText(Text* text); 222 225 void flush(void); 223 226 224 227 void draw(void) const; 225 228 226 229 void debug(void) const; 227 230
Note: See TracChangeset
for help on using the changeset viewer.