Alpha with SDL_BlitSurface not preserved

Hello everyone and sorry for my English, I use google translate.

Here is my problem, when I use TTF_RenderUNICODE_Blended to render with transparency and I copy the surface to another, the transparency is not preserved.

Can you help me ?

THANKS.

SDL_Surface *pSurface, *pLetter;
SDL_Color	colorText	= {255,255,255,255};
SDL_Rect     dest;
TTF_Font    *pFontTTF;

pFontTTF	= TTF_OpenFont("arial.ttf", 14);
 
pSurface	= SDL_CreateRGBSurface(0, 250, 250, 32, 0, 0, 0, 0);
SDL_SetSurfaceBlendMode(pSurface, SDL_BLENDMODE_BLEND);
SDL_SetColorKey(pSurface, SDL_TRUE, SDL_MapRGBA(pSurface->format, 0, 0, 0, 0));

pLetter = TTF_RenderUNICODE_Blended(pFontTTF, 65, color);	//	Render A

IMG_SavePNG(pLetter, "a.png");	//	preserves alpha

dest.x	= 0;
dest.y	= 0;
dest.w	= pLetter->w;
dest.h	= pLetter->h;
SDL_BlitSurface(pLetter, NULL, pSurface, &dest);

IMG_SavePNG(pLetter, "a-blit.png");	//	not preserves alpha

I think the problem is that you pass 0 for the masks to SDL_CreateRGBSurface. This will create a black surface without an alpha channel.

Thanks for your response, but even trying

SDL_CreateRGBSurface(0, 250, 250, 32, 0, 0, 0, 255);

the problem persists.

I think it’s either all zeros or your need to specify all the masks. It’s probably easier to use SDL_CreateRGBSurfaceWithFormat.

pSurface = SDL_CreateRGBSurfaceWithFormat(0, 250, 250, 32, SDL_PIXELFORMAT_RGBA8888);

it works.
Thank you very much for taking the time to help me.