• Advertisement
Sign in to follow this  

[MDX/C#] Overlay sample

This topic is 4423 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've ported the C++ overlay sample to C#. I've built it with the December SDK, but given that DirectDraw hasn't changed for a long time, you'll probably be able to build it with older SDKs too - especially since it doesn't use the sample framework (which changes often). Grab it here. Read the original thread that describes what the sample does here. The sample is public domain.

Share this post


Link to post
Share on other sites
Advertisement
Heya,

Thanks for doing this :)

I've just one question, and i find this strange.

On my work computer, this sample works flawlessly.

On my home computer, it errors out on creating the "overlaySurface" surface with an "InvalidPixelFormat" error. Only on my homer computer though.

My work machine is running an ATI X600, my home machine a nVidia 6800GT.

Any help would be greatly appreciated :)

Cheers,
Matt

Share this post


Link to post
Share on other sites
Quote:
Original post by McNubblet
On my home computer, it errors out on creating the "overlaySurface" surface with an "InvalidPixelFormat" error. Only on my homer computer though.

Could be that it doesn't support 32-bit overlays. Tried it with 16-bit ones?

Share this post


Link to post
Share on other sites
I've tried both unfortunately, same result. I was reading somewhere about "FourCCCodes" when it comes to overlays, i'm trying to understand what they're talking about now.

Cheers.

Share this post


Link to post
Share on other sites
Update:

I've done a bit more research and suspect that my card at home only supports 16bit "555" pixel format for overlays.

The 16bit pixel format in this example is "565" format.

I've change the BitsPerPixel enum to:

Code:

public enum BitsPerPixel
{
Bpp16555,
Bpp16565,
Bpp32
}


And the GetPixelFormat function to:
Code:

DirectDraw.PixelFormat GetPixelFormat(BitsPerPixel bpp)
{
DirectDraw.PixelFormat pixelFormat = new DirectDraw.PixelFormat();
pixelFormat.Rgb = true;

switch (bpp)
{
case BitsPerPixel.Bpp16555:
pixelFormat.RgbBitCount = 16;
pixelFormat.RBitMask = 0x7C00;
pixelFormat.GBitMask = 0x03E0;
pixelFormat.BBitMask = 0x001F;
break;

case BitsPerPixel.Bpp16565:
pixelFormat.RgbBitCount = 16;
pixelFormat.RBitMask = 0xF800;
pixelFormat.GBitMask = 0x07E0;
pixelFormat.BBitMask = 0x001F;
break;

case BitsPerPixel.Bpp32:
pixelFormat.RgbBitCount = 32;
pixelFormat.RBitMask = 0x00FF0000;
pixelFormat.GBitMask = 0x0000FF00;
pixelFormat.BBitMask = 0x000000FF;
break;


default:
throw new ArgumentOutOfRangeException("bpp", bpp, "Unexpected bit depth - neither 16 nor 32");
}

return pixelFormat;
}


Hopefully this should do the trick :)

Share this post


Link to post
Share on other sites
It didn't, i'm just about pulling my hair out with this one... :(

Is there a possible way to enumerate what PixelFormats are valid?

Cheers.

Share this post


Link to post
Share on other sites
Yes you can enumerate what pixel formats are supported by a device.

(1) Build an array of all possible pixel formats (there are not many 16/32bpp pixel formats) and loop through each one doing the following:

(2) Use GetAdapterModeCount (refer to directx9 SDK) to get the number of adaptor modes that use that pixel format.

(3) For each supported AdaptorMode use EnumAdapterModes to get a DisplayMode.

(4) Test the DisplayMode against any criteria you may have.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement