예제 #1
0
void Decorator::draw( Picture& dstpic, const Rect& rectangle, Mode mode, bool useAlpha, bool updateTexture )
{
  if( updateTexture )
    dstpic.lock();

  switch( mode )
  {
  /*case whiteArea: drawArea( dstpic, rectangle, 348, 10, 12, useAlpha ); break;
  case blackArea: drawArea( dstpic, rectangle, 487, 5, 7, useAlpha ); break;
  case greyPanel: drawPanel( dstpic, rectangle, 25, useAlpha ); break;
  case lightgreyPanel: drawPanel( dstpic, rectangle, 22, useAlpha ); break;
  case greyPanelBig: drawPanel( dstpic, rectangle, 631, useAlpha ); break;
  case lightgreyPanelBig: drawPanel( dstpic, rectangle, 634, useAlpha ); break;
  case greyPanelSmall: drawPanel( dstpic, rectangle, 68, useAlpha ); break;
  case brownPanelSmall: drawPanel( dstpic, rectangle, 65, useAlpha ); break;
  case whiteBorder: drawBorder( dstpic, rectangle, 336, 468, 347, 358, 10, 12, 335, 467, 346, 478, useAlpha );  break;
  case blackBorder: drawBorder( dstpic, rectangle, 480, 522, 486, 492, 5, 7, 479, 521, 485, 527, useAlpha ); break;
  case brownBorder: drawBorder(dstpic, rectangle, 555, useAlpha ); break;
  case whiteBorderA: drawBorder( dstpic, rectangle, 547, useAlpha ); break;
  case whiteFrame:
    draw( dstpic, Rect( rectangle.UpperLeftCorner + Point( 16, 16 ), rectangle.LowerRightCorner - Point( 16, 16 ) ), whiteArea );    // draws the inside of the box
    draw( dstpic, rectangle, whiteBorder );    // draws borders
  break;

  case blackFrame:
    draw(dstpic, Rect( rectangle.UpperLeftCorner + Point( 16, 16 ), rectangle.LowerRightCorner - Point( 16, 16 ) ), blackArea );    // draws the inside of the box
    draw(dstpic, rectangle, blackBorder );    // draws borders
  break;

  case brownFrame: drawFrame(dstpic, rectangle, 28, useAlpha); break;
  case greyFrame: drawFrame(dstpic, rectangle, 37, useAlpha); break;*/

  case lineBlackBorder:
  case lineWhiteBorder:
  {
    NColor color = mode == lineBlackBorder ? ColorList::black : ColorList::white;
    drawLine( dstpic, rectangle.lefttop(), rectangle.righttop(), color );
    drawLine( dstpic, rectangle.righttop()-Point(1,0), rectangle.rightbottom()-Point(1,0), color );
    drawLine( dstpic, rectangle.rightbottom()-Point(0,1), rectangle.leftbottom()-Point(0,1), color );
    drawLine( dstpic, rectangle.leftbottom(), rectangle.lefttop(), color );
  }
  break;

  default:
    Logger::warning( "!!! Unsupport draw instuctions" );
  break;
  }

  if( updateTexture )
    dstpic.unlock();
}
예제 #2
0
void GfxGlEngine::loadPicture(Picture& ioPicture)
{
   GLuint& texture(ioPicture.getGlTextureID());
   SDL_Surface *surface = ioPicture.getSurface();
   GLenum texture_format;
   GLint nOfColors;

   // SDL_Surface *surface2
   // get the number of channels in the SDL surface
   nOfColors = surface->format->BytesPerPixel;
   if (nOfColors == 4)     // contains an alpha channel
   {
      if (surface->format->Rmask == 0x000000ff)
         texture_format = GL_RGBA;
      else
         texture_format = GL_BGRA;
   }
   else if (nOfColors == 3)     // no alpha channel
   {
      if (surface->format->Rmask == 0x000000ff)
         texture_format = GL_RGB;
      else
         texture_format = GL_BGR;
   }
   else
   {
      THROW("Invalid image format");
   }

   if (texture == 0)
   {
      // the picture has no texture ID!
      // generate a texture ID
      glGenTextures( 1, &texture );
   }

   // Bind the texture object
   glBindTexture( GL_TEXTURE_2D, texture );

   // Set the texture's stretching properties
   glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
   glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );

   // Edit the texture object's image data using the information SDL_Surface gives us
   ioPicture.lock();
   glTexImage2D( GL_TEXTURE_2D, 0, nOfColors, surface->w, surface->h, 0,
                 texture_format, GL_UNSIGNED_BYTE, surface->pixels );
   ioPicture.unlock();
}