Advertisement

help with code

Started by February 14, 2000 10:33 AM
0 comments, last by uncreativ 25 years ago
could someone help me modify this code to allow transparency... i would like the transparent color to be 255,0,255. this is for 16bit color...

bool LoadImage(LPDIRECTDRAWSURFACE s, LPSTR szImage,int width, int height, POINT p) {
	HBITMAP		hbm;
	HDC			hdcImage = NULL;
	HDC			hdcSurf = NULL;
	bool		bReturn = FALSE;
	DDSURFACEDESC ddsd;


	ZeroMemory(&ddsd,sizeof(ddsd));
	ddsd.dwSize = sizeof(ddsd);
	s->GetSurfaceDesc(&ddsd);
	ddsd.dwWidth = width;
	ddsd.dwHeight = height;
	


	hbm = (HBITMAP)LoadImage(NULL,szImage,IMAGE_BITMAP, ddsd.dwWidth, ddsd.dwHeight, LR_LOADFROMFILE / LR_CREATEDIBSECTION );

	hdcImage = CreateCompatibleDC(NULL);
	SelectObject(hdcImage, hbm);

	s->GetDC(&hdcSurf);
	BitBlt(hdcSurf, p.x, p.y, ddsd.dwWidth, ddsd.dwHeight, hdcImage, 0, 0, SRCCOPY);

	bReturn = TRUE;

	s->ReleaseDC(hdcSurf);

	DeleteDC(hdcImage);
	DeleteObject(hbm);

	return bReturn;
}
any help would be greatly appreciated.
-uncreativpresidenthalosoft, inc.halosoft.hypermart.net
I don''t think you should edit that code... Why don''t you set a colorkey to your destination surface (maybe back buffer) and blit surface that contains image to destination surface...? Use lpDDSurface->SetColorKey() to set your colorkey (I think DirectX manual or examples can help you how to use it). You can set colorkey to your surface that contains image, too if you''re sure that your display card supports it.

Oh... Don''t forget to set the flag DDBLT_DSTCOLORKEY or DDBLT_SRCCOLORKEY when you blit surface that contains image to destination surface, too...

Hope it helps...

This topic is closed to new replies.

Advertisement