用于在全屏游戏上画东西,写字。
$ R+ P/ t5 T1 h+ W& \+ D7 c7 m: k% O& c' o; @
原文
& y8 P, c* L6 Lhttp://www.gamedev.net/community/forums/topic.asp?topic_id=3593192 B1 R+ H7 u7 D, U
; ]' x% ~- l- T" ^0 ?
A lot of people seem interested in knowing how to render content over full-screen applications, like XFire and Co, judging by the number of posts about it. Here’s an unmanaged overlaying sample. Visual Studio 2003 and 2005 solutions are included.
; R# {0 @" W1 _* P* H
T% E( U, Z( @7 V4 `The sample uses DirectDraw overlays to render a black 256x64 box to the top-left of the screen, with some text in it. I would’ve shown you a screenshot, but I can’t, due to the way overlays work. Overlays are displayed as the device is painting the monitor from the primary surface. If it’s painting a location where an overlay exists, it paints the monitor with its color instead of the primary surface. Consequently, you can’t capture that in an image.3 u, p o) w5 E* n1 W" B
* B) N1 |- ?1 ?# vBack to the sample. The files of interest are:
j" H! F7 M" mOverlay.cpp: Window creation (auto-generated, nothing interesting) and the main loop (important).8 V5 _. R) |8 z; C5 ~
overlay_renderer.h, overlay_renderer.cpp: The core of the sample. The code is fairly self-explanatory, though.
. |% R; N$ }2 [' B( [/ R, H& ~; q* W& d
One important thing to keep in mind is that overlay support comes with a set of limitations. The following limitations are not checked or accounted for in the sample:
6 H0 t& W( Q0 S. r3 b! k) P2 |% _4 adwAlignBoundarySrc0 s) v u8 q o/ E' w6 o
dwAlignSizeSrc
! G# r' b* ?% [2 {; cdwAlignBoundaryDest" t8 _' W$ r( x+ Y
dwAlignSizeDest! Y# w/ e* D" w4 B1 D# t
dwAlignStrideAlign
( U6 E( ^, e! e' Z7 w8 T) [dwMinOverlayStretch
% S1 e2 }5 v1 N3 P8 N& fdwMaxOverlayStretch; P6 P( Z- G7 o
: D& ~7 l" _( j: M0 _8 X
The limitations are hardware-dependent. For example, my X300 doesn’t impose any alignment restrictions for the source or destination overlay rectangles. In a product, however, you’d want to make sure you check for these and abide by them. Use CapsViewer to find out the limitations of your hardware quickly. I don’t know if the October SDK caps database includes DirectDraw caps or not, but consider checking it out.9 a: I6 N* R1 G
0 ^3 v. V; i) }% C/ F7 D f
The limitations (and overlays in general) are documented under “DirectDraw->DirectDraw Essentials->Surfaces->Overlay Surfaces” in the DX7 documentation. It’s available at icarusIndie.; ^, y0 h% u: o4 M: U% [
5 Z6 H4 E7 \# j% w/ g9 WI might write a managed port, if someone’s interested. All feedback’s welcome. |