Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 1, 2005, 11:51:44 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: graphicsEngine and TextEngine documented

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/lib/graphics/text_engine.cc

    r4320 r4458  
    7676}
    7777
    78 
     78/**
     79   \brief tells the Text, that it should folow a PNode
     80   \param bindNode: the node to bind this text to
     81*/
    7982void Text::setBindNode(PNode* bindNode)
    8083{
     
    277280
    278281////////////
     282/// UTIL ///
     283////////////
     284/**
     285   \brief Loads a Font from an SDL_surface into a texture.
     286   \param surface The surface to make the texture of
     287   \param texCoord The texture coordinates of the 4 corners of the texture
     288   \returns the ID of the texture
     289*/
     290GLuint Text::loadTexture(SDL_Surface *surface, TexCoord* texCoord)
     291{
     292  GLuint texture;
     293  int w, h;
     294  SDL_Surface *image;
     295  SDL_Rect area;
     296  Uint32 saved_flags;
     297  Uint8  saved_alpha;
     298 
     299  /* Use the surface width and height expanded to powers of 2 */
     300  w = powerOfTwo(surface->w);
     301  h = powerOfTwo(surface->h);
     302  if (texCoord)
     303    {
     304      texCoord->minU = 0.0f;
     305      texCoord->minV = 0.0f;
     306      texCoord->maxU = (GLfloat)surface->w / w;
     307      texCoord->maxV = (GLfloat)surface->h / h;
     308    }
     309  image = SDL_CreateRGBSurface(SDL_SWSURFACE,
     310                               w, h,
     311                               32,
     312#if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
     313                               0x000000FF,
     314                               0x0000FF00,
     315                               0x00FF0000,
     316                               0xFF000000
     317#else
     318                               0xFF000000,
     319                               0x00FF0000,
     320                               0x0000FF00,
     321                               0x000000FF
     322#endif
     323                               );
     324  if ( image == NULL ) {
     325    return 0;
     326  }
     327 
     328  /* Save the alpha blending attributes */
     329  saved_flags = surface->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
     330  saved_alpha = surface->format->alpha;
     331  if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
     332    SDL_SetAlpha(surface, 0, 0);
     333  }
     334 
     335  /* Copy the surface into the GL texture image */
     336  area.x = 0;
     337  area.y = 0;
     338  area.w = surface->w;
     339  area.h = surface->h;
     340  SDL_BlitSurface(surface, &area, image, &area);
     341 
     342  /* Restore the alpha blending attributes */
     343  if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
     344    SDL_SetAlpha(surface, saved_flags, saved_alpha);
     345  }
     346 
     347  /* Create an OpenGL texture for the image */
     348  glGenTextures(1, &texture);
     349  glBindTexture(GL_TEXTURE_2D, texture);
     350  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
     351  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
     352  glTexImage2D(GL_TEXTURE_2D,
     353               0,
     354               GL_RGBA,
     355               w, h,
     356               0,
     357               GL_RGBA,
     358               GL_UNSIGNED_BYTE,
     359               image->pixels);
     360  SDL_FreeSurface(image); /* No longer needed */
     361 
     362  return texture;
     363}
     364
     365/**
     366   \brief Quick utility function for texture creation
     367   \param input an integer
     368   \returns the next bigger 2^n-integer than input
     369*/
     370int Text::powerOfTwo(int input)
     371{
     372  int value = 1;
     373 
     374  while ( value < input ) {
     375    value <<= 1;
     376  }
     377  return value;
     378}
     379
     380
     381////////////
    279382/// FONT ///
    280383////////////
     
    358461   i: italic, b: bold, u, underline
    359462*/
    360 void Font::setStyle(char* renderStyle)
     463void Font::setStyle(const char* renderStyle)
    361464{
    362465  this->renderStyle = TTF_STYLE_NORMAL;
     
    690793}
    691794
    692 ////////////
    693 /// UTIL ///
    694 ////////////
    695 /**
    696    \brief Loads a Font from an SDL_surface into a texture.
    697    \param surface The surface to make the texture of
    698    \param texCoord The texture coordinates of the 4 corners of the texture
    699    \returns the ID of the texture
    700 */
    701 GLuint loadTexture(SDL_Surface *surface, TexCoord* texCoord)
    702 {
    703   GLuint texture;
    704   int w, h;
    705   SDL_Surface *image;
    706   SDL_Rect area;
    707   Uint32 saved_flags;
    708   Uint8  saved_alpha;
    709  
    710   /* Use the surface width and height expanded to powers of 2 */
    711   w = powerOfTwo(surface->w);
    712   h = powerOfTwo(surface->h);
    713   if (texCoord)
    714     {
    715       texCoord->minU = 0.0f;
    716       texCoord->minV = 0.0f;
    717       texCoord->maxU = (GLfloat)surface->w / w;
    718       texCoord->maxV = (GLfloat)surface->h / h;
    719     }
    720   image = SDL_CreateRGBSurface(SDL_SWSURFACE,
    721                                w, h,
    722                                32,
    723 #if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
    724                                0x000000FF,
    725                                0x0000FF00,
    726                                0x00FF0000,
    727                                0xFF000000
    728 #else
    729                                0xFF000000,
    730                                0x00FF0000,
    731                                0x0000FF00,
    732                                0x000000FF
    733 #endif
    734                                );
    735   if ( image == NULL ) {
    736     return 0;
    737   }
    738  
    739   /* Save the alpha blending attributes */
    740   saved_flags = surface->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
    741   saved_alpha = surface->format->alpha;
    742   if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
    743     SDL_SetAlpha(surface, 0, 0);
    744   }
    745  
    746   /* Copy the surface into the GL texture image */
    747   area.x = 0;
    748   area.y = 0;
    749   area.w = surface->w;
    750   area.h = surface->h;
    751   SDL_BlitSurface(surface, &area, image, &area);
    752  
    753   /* Restore the alpha blending attributes */
    754   if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
    755     SDL_SetAlpha(surface, saved_flags, saved_alpha);
    756   }
    757  
    758   /* Create an OpenGL texture for the image */
    759   glGenTextures(1, &texture);
    760   glBindTexture(GL_TEXTURE_2D, texture);
    761   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    762   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    763   glTexImage2D(GL_TEXTURE_2D,
    764                0,
    765                GL_RGBA,
    766                w, h,
    767                0,
    768                GL_RGBA,
    769                GL_UNSIGNED_BYTE,
    770                image->pixels);
    771   SDL_FreeSurface(image); /* No longer needed */
    772  
    773   return texture;
    774 }
    775 
    776 /**
    777    \brief Quick utility function for texture creation
    778    \param input an integer
    779    \returns the next bigger 2^n-integer than input
    780 */
    781 int powerOfTwo(int input)
    782 {
    783   int value = 1;
    784  
    785   while ( value < input ) {
    786     value <<= 1;
    787   }
    788   return value;
    789 }
    790 
    791 
    792 
    793 
    794 
    795795
    796796///////////////////
     
    893893/**
    894894   \brief removes a Text from the List
    895    \param the text to delete
     895   \param text: the text to delete
    896896
    897897   this only ereases allocated memory, and removes the text
Note: See TracChangeset for help on using the changeset viewer.