PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

no wait - what about alpha blending + rotation

I'm trying to rotate and resize an alpha blended image, however I'm having trouble finding the correct method. The alphablt result is an oversized image. Here's my code


Code:


//blit the surfaces into the correct position & size using temporary surfaces
srcCopy->Blt(NULL, srcSurface, NULL,
GDBLT_ROTATIONANGLE |
GDBLT_ROTATIONSCALE,
&bltfx;);

alphaCopy->Blt(NULL, alphaSurface, NULL,
GDBLT_ROTATIONANGLE |
GDBLT_ROTATIONSCALE,
&bltfx;);


RECT imagerect;
::SetRect(&imagerect;, 0, 0,
srcCopy->GetWidth(), srcCopy->GetHeight());

RECT alpharect;
::SetRect(&alpharect;, 0,0,
alphaCopy->GetWidth(), alphaCopy->GetHeight());

//blit the temporary surfaces onto the display
pBackBuffer->AlphaBlt(NULL,srcCopy,&imagerect;,alphaCopy,&alpharect;,GDALPHABLT_OPACITY, α);




The result of this is an image that hasn't been properly scaled. Do the temporary surfaces cause this problem by not being scaled themselves or something?
I just wanted to add this:

I may have confused the issue a bit by setting the GDBLT_ROTATIONSCALE flag since I know that the image will be scaled. However, the problem is not that it is scaled, but that it is scaled to a size that I didn't desire. I use Blt just before the code that I posted, and it blits a surface directly to the screen with the GDBLT_ROTATIONSCALE set and the same GDBLTFX structure being used but it shows up on the screen scaled by a different amount than the alpha blended image does in the code I posted.

Why is that?
so the GDBLT_ROTATIONSCALE in this code:

Code:

srcCopy->Blt(NULL, srcSurface, NULL,
GDBLT_ROTATIONSCALE,
&bltfx;);



doesn't seem to affect anything since if I later blit srcCopy to the screen without any scale flag set it appears at regular size. So does that mean that GDBLT_ROTATIONSCALE is just some sort of temporary scaling? Since if I was blitting to the screen directly in the above code the scaling would be correct.

The real question I have is how do you scale an image which you've alpha blended? Since in my original post I blended two images and once I got to the screen blit I can't scale the image!
here's a simpler question:

if you load in a .png with transparency information then you must use a CGapiRGBASurface to preserve it correct? So then how do you rotate or resize that surface?
Hi newbie,

CGapiSurface objects do not store alpha information. You can use two surfaces for alpha blends - where one surface contains the image and one contains the alpha.

CGapiRGBASurface objects store alpha information, but they support less features.

So you have to choose. You cannot AlphaBlt first, and then try to do something with the results and keep the variable opacity. In 99,9% of all cases you don't really need to copy in two steps anyway...
Thanks but I still have a question,

what if I want to alpha blend and resize? Can you post a little sample for me.
Resizing is simple. Just change the size of the source rectangle.

Try:
CRect srcrect(0, 0, srcsurface->GetWidth(), srcsurface->GetHeight());
destsurface->AlphaBlt(NULL, srcsurface, srcrect, ...);

If you make the source rectangle smaller, the result will be an "upsizing" during the blit.
Hello,

thanx again, but I still have problems.

I can "upsize" the image, but when I try to "downsize" the image it just disappears.

I might as well ask this question as well:
what about rotating a CGapiRGBASurface?
To downsize, simply adjust the _destination_ rectangle.

Rotation of CGapiRGBASurfaces is not implemented, but since you can get access to the raw surface buffer (GetBuffer) you can add it yourself if you want it...
OH,

thank you very much for your help - I can resize both ways now!

so I will have to deal with the buffer to do a rotate, sounds difficult - hopefully it won't be