cancel
Showing results for 
Search instead for 
Did you mean: 

How to draw sprites using DMA2D with transparency?

IGama.1
Associate

Hello ,

I am using STM32F429I-Discovery board I want to draw sprites on TFT-LCD with transparency on top of background image , I used black color as the transparent color for the images that I want to draw and used DMA2D at blending mode but the black color is not transparent and the sprite was drawn with a black color surrounding it.

the sprite color mode is RGB565 (I have tried ARGB888 also with no hope) .

The code :

void DrawSprite(uint32_t img , uint32_t SprNo , uint32_t w , uint32_t h  , int format)
{
	/* Configure the DMA2D Mode, Color Mode and output offset */
	  Dma2dHandle.Instance          = DMA2D;
	  Dma2dHandle.Init.ColorMode    = DMA2D_RGB565;
	  Dma2dHandle.Init.OutputOffset = 240 - w ;
 
	  /* Foreground Configuration */
	  Dma2dHandle.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
	  Dma2dHandle.LayerCfg[1].InputAlpha = 0xFF;
	  Dma2dHandle.LayerCfg[1].InputColorMode = format;
	  Dma2dHandle.LayerCfg[1].InputOffset = 0;
 
 
 
	  if(SprNo == BACKGROUND)
	  {
		  Dma2dHandle.Init.Mode = DMA2D_M2M ;
	  }
	  else
	  {
		  Dma2dHandle.Init.Mode = DMA2D_M2M_BLEND ;
 
		  /* Foreground Configuration */
		  Dma2dHandle.LayerCfg[0].AlphaMode = DMA2D_NO_MODIF_ALPHA;
		  Dma2dHandle.LayerCfg[0].InputAlpha = 0xFF;
		  Dma2dHandle.LayerCfg[0].InputColorMode = DMA2D_INPUT_RGB565;
		  Dma2dHandle.LayerCfg[0].InputOffset = Dma2dHandle.Init.OutputOffset;
 
		  /* Configure DMA2D Stream source2 address */
		  WRITE_REG(Dma2dHandle.Instance->BGMAR, (uint32_t)RenderBuffer);
	  }
 
 
	  /* DMA2D Initialization */
	  HAL_DMA2D_Init(&Dma2dHandle);
 
	  HAL_DMA2D_ConfigLayer(&Dma2dHandle, 1);
	  if(SprNo != BACKGROUND)
		     HAL_DMA2D_ConfigLayer(&Dma2dHandle, 0);
 
	  /*DMA2D Transfer Start*/
	  HAL_DMA2D_Start(&Dma2dHandle,(uint32_t) img, (uint32_t)RenderBuffer, w, h );
	  HAL_DMA2D_PollForTransfer(&Dma2dHandle, 100);
}

0693W000008wq2gQAA.jpg

0 REPLIES 0