DirectDraw
Issues
How Can
I Draw a Pixel Directly to a DirectDraw Surface?
How
can I load images onto surfaces with a different pixel format?
Why does my Color Key
fail when using 16 bit color depth?
Why does my full
screen DirectDraw application drop frames at times, displaying a black screen
momentarily?
What are the equations to covert
between Y'UV and RGB color?
Q. How Can I Draw a Pixel Directly to a
DirectDraw Surface?
There are several ways this can be accomplished, but overall the
preferred method in most instances is to retrieve a pointer to the surface
memory using the Lock() function, and writing color values into the memory
location on the surface corresponding to the coordinate of the pixel. Some
cautionary notes to observe when using Lock().
-
Do not assume the width of a scan line, as there may be
additional bytes attached to each scan line for such purposes as alignment
or caching. The width of a scan line can be attained from the lPitch
element of the surface description returned by Lock().
-
Minimize the duration of the Lock(), or performance will
suffer. This is because the Lock() command signals a Win16MuteX, which
in effect prevents the messaging system and other windows threads from
continuing until it is released.
-
Each Lock() must be completed with a matching Unlock()
command. While the surface is locked, any attempts to blit to the
surface will fail.
Back to the Top
Back to Main Index
Q. How can I load images onto
surfaces with a different pixel format?
Converting the pixel format is processor intensive, so you will
want to perform the conversion once when you load the image. GDI can be
used to perform this conversion for you - check out the article Color
Depth Conversion of Bitmaps Using GDI for a quick tutorial, including source
code for a function that handles image loading, format conversion, and color key
setup in one quick step.
Back to the Top
Back to Main Index
Q. Why does my Color Key fail when
using 16 bit color depth?
16 bit color depth is supported through several different bit
arrangements, including 5-5-5 and 5-6-5. This is dependant upon the video
hardware and driver, so you must determine what the pixel value for your color
key will be at run time.
This may be accomplished by reading the pixel format using
IDirectDrawSurface::GetPixelFormat() and examining the bitmask values for each
color channel, returned in dwBBitMask / dwGBitMask / dwRBitMask members of the
structure filled by this function. For example, if we were using a
saturated green key (RGB 0,255,0) we could use the following code to determine
the proper key value to set:
DDPIXELFORMAT pf;
ZeroMemory(&pf,sizeof(pf));
pf.dwSize=sizeof(pf);
lpDDSPrimary->GetPixelFormat(&pf);
DWORD KeyColor=pf.dwGBitMask;
Back to the Top
Back to Main Index
Q. Why does my full screen DirectDraw
application drop frames at times, displaying a black screen momentarily?
This can happen when a WM_PAINT message is received by the
application. This triggers a WM_ERASEBKGND message, calling for the client
surface to be erased. The default Windows procedure will clear to the
currently set background brush, thus clearing the screen.
To avoid this, override this message to simply return TRUE,
which notifies Windows that no further action is needed to clear the window:
case WM_ERASEBKGND:
return TRUE;
break;
Back to the Top
Back to Main Index
Q. What are the equations to covert
between Y'UV and RGB color?
The following equations convert between RGB and Y'UV:
R = Y + (1.4075 * (V - 128));
G = Y - (0.3455 * (U - 128) -
(0.7169 * (V - 128));
B = Y + (1.7790 * (U - 128);
Y = R * 0.299 + G * 0.587 + B *
0.114;
U = R * -0.169 + G * -0.332 + B * 0.500 + 128;
V = R * 0.500 + G * -0.419 + B
* -0.0813 + 128;
Back to the Top
Back to Main Index