Ejemplo n.º 1
0
bool CTexture::FillTextureWithColor (unsigned int width, unsigned int height, const CColor& color)
{
  if (m_Texture==NULL)
  {
    LOGGER->AddNewLog(ELL_ERROR,"CTexture::FillTextureWithColor-> m_Texture no ha sido creado aun ");
    return false;
  }

  HRESULT hr;
  D3DLOCKED_RECT lock;
  hr=m_Texture->LockRect(0, &lock, NULL, D3DLOCK_DISCARD);
  if(hr==D3D_OK)
  {
    uint8 *pTxtBuffer; // Bitmap buffer, texture buffer
    pTxtBuffer = (uint8*)lock.pBits;

		
    uint32 j = 0;
    for( uint32 cont = 0; cont< width * height; cont++)
    {
      //BLUE
      pTxtBuffer[cont*4 + 0] = (uint8)(color.GetBlue()*255);
      //GREEN
      pTxtBuffer[cont*4 + 1] = (uint8)(color.GetGreen()*255);
      //RED
      pTxtBuffer[cont*4 + 2] = (uint8)(color.GetRed()*255);
      //ALPHA
      pTxtBuffer[cont*4 + 3] = (uint8)(color.GetAlpha()*255);
    }
    hr=m_Texture->UnlockRect(0);
  }
  else
  {
    LOGGER->AddNewLog(ELL_ERROR,"CTexture::FillTextureWithColor->Error en la llamada lockRect");
    return false;
  }

	m_Width	= width;
	m_Height	= height;

  return true;
}
Ejemplo n.º 2
0
void DX9SpriteBatch::Draw(
	ITextureBase *Texture2D, CRectangle &PositionInTexture, 
	Vector2I &Origin, Vector2F &Position, 
	float Rotation, Vector2F &Scale, CColor &Color, 
	float ZOrder, eSpriteEffects SpriteEffect )
{
	CDX9Texture *tex = dynamic_cast<CDX9Texture *>(Texture2D);
	RECT src;
	src.left = PositionInTexture.Left();
	src.right = PositionInTexture.Right();
	src.top = PositionInTexture.Top();
	src.bottom = PositionInTexture.Bottom();
	D3DXVECTOR2 center(static_cast<float>(Origin.x), static_cast<float>(Origin.y));
	D3DXVECTOR2 pos(Position.x - Origin.x, Position.y - Origin.y);

	D3DXMATRIX transform;
	DXCheck(D3DXMatrixTransformation2D(&transform, NULL, NULL, &D3DXVECTOR2(Scale.x, Scale.y), &center, Rotation, &pos));

	if (SUCCEEDED(DXCheck(m_D3DSprite->SetTransform(&transform))))
	{
		DXCheck(m_D3DSprite->Draw( tex->GetDxTexture(), &src, NULL, NULL,
				D3DCOLOR_RGBA(Color.GetRed(), Color.GetGreen(), Color.GetBlue(), Color.GetAlpha()) ));
	}	
}