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;
}
pitch of a directdraw surface in 16 bits
Hey,
I'm trying to use directdraw in 16bits. I initialize directdraw with that function:
I use a width and height of 400 in the function above.
the pitch returned by surface_desc->lPitch is 832 and not 800, with surface_desc is the description of my surface. Can someone explain why ?
(note that surface_desc->ddpfPixelFormat.dwRGBBitCount gives 16)
thank you
It depends on the video card. The pitch just tells you how many bytes are used for a single row of pixels. The first 400 pixels produce 800 contiguous bytes, but the manufacturer attaches an additional 32 bytes to the end for their driver, bytes you should never access. You just need to realize that a row is 832 bytes, so when you are finished working with the 800 bytes, add 32 to your pointer or add 32*CurrentRow to your row starting point calculation.
I'm sure you've heard it already, but you should look into using Direct3D. I started out with DirectDraw and it is a good way to get a better understanding of how the video card works on a lower level, but it is complex and pretty much useless now days, so don't spend too much time on it.
Chris
I'm sure you've heard it already, but you should look into using Direct3D. I started out with DirectDraw and it is a good way to get a better understanding of how the video card works on a lower level, but it is complex and pretty much useless now days, so don't spend too much time on it.
Chris
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement