-
Alpha Channel!?!
It's me again! x)
I have gotten most of my project done, Now I need to find out how to draw the object with an alpha channel to the MMF frame at runtime/edittime...
It works perfect as long as the image does not contain an alpha channel.. but otherwise it just wont display..
Any tutorials on this? Or maybe someone who can share a snippet of code?
Thanks!
-
Re: Alpha Channel!?!
I think I did something like this:
In CreateRunObject:
Code:
::LockImageSurface (rhPtr->rhIdAppli, edPtr->imgidx, imageSurface, LOCKIMAGE_READBLITONLY);
// get size
rdPtr->swidth = rdPtr->oldwidth = imageSurface.GetWidth();
rdPtr->sheight = rdPtr->oldheight = imageSurface.GetHeight();
rdPtr->rHo.hoImgWidth = rdPtr->swidth;
rdPtr->rHo.hoImgHeight = rdPtr->sheight;
LPSURFACE pProto = NULL;
int Test = imageSurface.GetDepth();
if ( GetSurfacePrototype(&pProto, imageSurface.GetDepth(), ST_MEMORYWITHPERMANENTDC, SD_DIB) )
{
// OK
rdPtr->runSurface = new cSurface;
if (rdPtr->runSurface != NULL)
{
rdPtr->runSurface->Create(rdPtr->swidth,rdPtr->sheight,pProto);
imageSurface.Blit(*rdPtr->runSurface,0,0,BMODE_OPAQUE,BOP_COPY,0);
if(imageSurface.HasAlpha()==true)
{
rdPtr->runSurface->CreateAlpha();
LPBYTE mAlpha= imageSurface.LockAlpha();
rdPtr->runSurface->SetAlpha(mAlpha,imageSurface.GetAlphaPitch());
imageSurface.UnlockAlpha();
}
}
}
::UnlockImageSurface (imageSurface);
Not sure if that is all of it or if it is totally correct code.
-
Re: Alpha Channel!?!
Vortex you shouldn't have to do that, if you do a simple Blit, or a Clone, then the alpha channel is automatically copied. If for any reason it's not copied, you can use BLTF_COPYALPHA in the dwBlitFlags parameter of the Blit function.
Daniel, you should post your code, because theoretically you have nothing to do, the alpha channel is automatically taken into account.
-
Re: Alpha Channel!?!
Thanks... This is my current code... With this code, no alpha channel is displayed, instead the alpha in the image is blended with black =\
Creating the main surface
Code:
rdPtr->pSf = NULL;
LPRH rhPtr = rdPtr->rHo.hoAdRunHeader;
LPSURFACE wSurf = WinGetSurface((int)rhPtr->rhIdEditWin);
LPSURFACE proto;
GetSurfacePrototype(&proto, (wSurf != NULL) ? wSurf->GetDepth() : 24, ST_MEMORYWITHDC, SD_DIB);
if (proto != NULL) {
// Create surface
cSurface* psf = NewSurface();
if ( psf != NULL ) {
psf->Create(rdPtr->nWidth, rdPtr->nHeight, proto);
psf->Fill(RGB(255,0,0));
if ( psf->GetDepth() == 8 )
psf->SetPalette (*wSurf);
if ( rdPtr->pSf != NULL )
DeleteSurface(rdPtr->pSf);
rdPtr->pSf = psf;
}
}
Drawing to the surface
Code:
fprh rhPtr = rdPtr->rHo.hoAdRunHeader;
LPSURFACE ps = WinGetSurface((int)rhPtr->rhIdEditWin);
LPSURFACE pProto = NULL;
int xsize=rdPtr->rHo.hoRect.right-rdPtr->rHo.hoRect.left;
int ysize=rdPtr->rHo.hoRect.bottom-rdPtr->rHo.hoRect.top;
cSurface imgSurf;
LockImageSurface (rhPtr->rhIdAppli, rdPtr->wImgIdx[f], imgSurf, LOCKIMAGE_READBLITONLY);
imgSurf.Blit(*rdPtr->pSf, x, y, 0, 0, w, h, BMODE_TRANSP, BOP_COPY, 0, BLTF_COPYALPHA);
UnlockImageSurface (imgSurf);
rdPtr->pSf->Blit(*ps,rdPtr->rHo.hoRect.left,rdPtr->rHo.hoRect.top,0,0,xsize,ysize,
(BlitMode)(rdPtr->rHo.hoOiList->oilInkEffect>>28), //BMODE_TRANSP,
(BlitOp)((rdPtr->rHo.hoOiList->oilInkEffect<<16)>>16), //BOP_COPY,
rdPtr->rHo.hoOiList->oilEffectParam,
BLTF_COPYALPHA);
WinAddZone(rhPtr->rhIdEditWin, &rdPtr->rHo.hoRect);
Cheers!
-
Re: Alpha Channel!?!
I can assure you that I exhausted all options at the time when I wrote that code and that was the only way that worked. I believe there was a bug in the routines that caused rendering issues if you tried to copy a surface that had an alpha channel to a surface that didn't originally have an alpha channel (because in my extension the alpha channel was optional).
-
Re: Alpha Channel!?!
I have tried alot to.. even the way you describe Vortex.. still wont work.. The alpha channel is optional in my extension to!
-
Re: Alpha Channel!?!
Daniel, you must not use BLTF_COPYALPHA in the second Blit (rdPtr->pSf->Blit(*ps, etc...)).
BLTF_COPYALPHA copies the alpha channel from the source surface to the destination surface. In the second Blit, you display the image to the main display surface, so the alpha channel must not be copied, it must be used by the display routine to display the pixels of your images with a semi-transparency.
-
Re: Alpha Channel!?!
Thanks for the info! ^^
I'll try it out as soon as I have reinstalled VC++... I'm on a new Laptop atm! :)
-
Re: Alpha Channel!?!
I still get the same result =\
-
Re: Alpha Channel!?!
No other idea, I would need to see and debug the whole source code.