PDA

View Full Version : adding alpha to a self-created direct draw surface


cliffski
10-28-2006, 06:58 AM
ok here goes....
I use FreeImage to load in a JPG file (works great) I then create a direct draw surface of the right size, and copy the data from the free image loaded bitmap into it, so that my directx calls can use it (works great).
I now have some nifty system for loading in a bitmap thats just got alpha data in it, and I want to apply this alpha data to my earlier loaded jpg data (I want jpg compression, but with alpha)
Anyway, it doesn't work, and it looks like it doesn't work because the surface I created to stick my jpg data in has no idea where its alpha should be.

If I just load in a standard bitmap (letting d3dx handle the loading) and apply my alpha to that, it works just dandy, but that defeats the object of the exercise.
Am I right in guessing that I need to somehow set up lots of DDSURFACEDESC2 and DDCAPS data on the surface that I am creating (the one I put the jpg data in)
Feel free to tell me I'm insane and should be doing it another way entirely.

luggage
10-28-2006, 07:02 AM
What pixel format are you using when you create the surface you load the jpg onto?

cliffski
10-28-2006, 07:08 AM
this is all I do:


DDSCAPS2 ddsCaps;
DDSURFACEDESC2 ddsd;

ZeroMemory(&ddsd,sizeof(ddsd));
ddsd.dwSize=sizeof(ddsd);
ZeroMemory(&ddsCaps,sizeof(ddsCaps));

ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;

ddsd.dwHeight = FreeImage_GetHeight(fimage);
ddsd.dwWidth = FreeImage_GetWidth(fimage);
ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;


This isn't enough is it?

luggage
10-28-2006, 08:28 AM
Try adding DDSD_ALPHABITDEPTH to the dwFlags.

And then set the ddsd.dwAlphaBitDepth to something useful. It might be that. You may also have to do something with ddpfPixelFormat.

Fingers crossed.

cliffski
10-28-2006, 08:33 AM
yeah ive spent hours on it now. tried all that ;(
it doesnt seem to like it. I tried passing in the surfacedesc from a working loaded bitmap, it didnt like that either. bizzare.
im now resorting to using a dummy bitmap of the same size to see if i can copy the jpg data into that!

Nikster
10-28-2006, 04:38 PM
If you're using freeimage, why not use the convertto32bit and setchannel features ?