1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
static int
_directdraw_init (HWND window,
LPDIRECTDRAW *object,
LPDIRECTDRAWSURFACE *surface_primary,
LPDIRECTDRAWSURFACE *surface_back,
int *depth,
int width,
int height)
{
DDSURFACEDESC2 surface_desc;
DDPIXELFORMAT pixel_format;
LPDIRECTDRAWCLIPPER clipper;
LPDIRECTDRAW o;
DDSURFACEDESC2 *sd;
HRESULT res;
res = DirectDrawCreateEx (NULL, (void **)&o, &IID_IDirectDraw7, NULL);
if (FAILED(res))
return 0;
res = IDirectDraw7_SetCooperativeLevel (o, window, DDSCL_NORMAL);
if (FAILED(res))
{
IDirectDraw7_Release (o);
return 0;
}
res = IDirectDraw7_CreateClipper (o, 0, &clipper, NULL);
if (FAILED(res))
{
IDirectDraw7_Release (o);
return 0;
}
res = IDirectDrawClipper_SetHWnd (clipper, 0, window);
if (FAILED(res))
{
IDirectDrawClipper_Release (clipper);
IDirectDraw7_Release (o);
return 0;
}
memset(&surface_desc, 0, sizeof(surface_desc));
surface_desc.dwSize = sizeof(surface_desc);
surface_desc.dwFlags = DDSD_CAPS;
surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
sd=&surface_desc;
res = IDirectDraw7_CreateSurface (o, &surface_desc,
surface_primary, NULL);
if (FAILED(res))
{
IDirectDrawClipper_Release (clipper);
IDirectDraw7_Release (o);
return 0;
}
res = IDirectDrawSurface7_SetClipper (*surface_primary, clipper);
if (FAILED(res))
{
IDirectDrawClipper_Release (clipper);
IDirectDrawSurface7_Release (*surface_primary);
IDirectDraw7_Release (o);
return 0;
}
memset (&surface_desc, 0, sizeof(surface_desc));
surface_desc.dwSize = sizeof(surface_desc);
surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
surface_desc.dwWidth = width;
surface_desc.dwHeight = height;
sd=&surface_desc;
res = IDirectDraw7_CreateSurface (o, (DDSURFACEDESC *)sd,
surface_back, NULL);
if (FAILED(res))
{
IDirectDrawClipper_Release (clipper);
IDirectDrawSurface7_Release (*surface_primary);
IDirectDraw7_Release (o);
return 0;
}
ZeroMemory(&pixel_format, sizeof(pixel_format));
pixel_format.dwSize = sizeof(pixel_format);
IDirectDrawSurface7_GetPixelFormat(*surface_primary, &pixel_format);
*object = o;
*depth = pixel_format.dwRGBBitCount;
return 1;
} |
Partager