用于在全屏游戏上画东西,写字。6 X1 m: z4 T$ Q1 V o
( Z$ E4 v9 M. s原文
' c: U: o0 K5 h t* E, F# j& |' l$ whttp://www.gamedev.net/community/forums/topic.asp?topic_id=359319
: a- P, u: e4 S& I" m' m0 s3 l+ [5 w
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+ E) O' T" T( E; A& I
3 h) ^% M/ h* ?
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./ u9 S; x7 [# {
$ r& C# V0 V7 e: N5 s- dBack to the sample. The files of interest are:
3 C- Z5 g7 T% h' p b$ nOverlay.cpp: Window creation (auto-generated, nothing interesting) and the main loop (important)." f" Z' x. z0 e4 A: N$ s
overlay_renderer.h, overlay_renderer.cpp: The core of the sample. The code is fairly self-explanatory, though.8 \1 S ]+ s, k7 c
% f: ^5 Y9 C; v# M
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:! U2 D4 x' u( j1 u; Z2 c
dwAlignBoundarySrc
4 }; ]9 T3 m8 }" _4 i: E2 _dwAlignSizeSrc1 g7 T3 e* l( M$ q: m2 B0 T- W) b
dwAlignBoundaryDest
+ w" D+ K' x' D2 V9 h$ udwAlignSizeDest
; f' u& m9 y8 D$ D" Y4 C/ XdwAlignStrideAlign
0 n1 b) i& ^$ V W' E2 GdwMinOverlayStretch / i/ o5 I+ L# x1 ^, E7 p2 j
dwMaxOverlayStretch+ P/ r$ o' O w. ]; Q+ [. R8 g9 S* k. `5 t
7 K8 t/ e5 ~3 u y" ]1 gThe 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.! j( K! l [* U; ?+ ~( O
$ X& i8 N4 u; S1 f& q1 c" W1 p4 }
The limitations (and overlays in general) are documented under “DirectDraw->DirectDraw Essentials->Surfaces->Overlay Surfaces” in the DX7 documentation. It’s available at icarusIndie.2 E5 S( B6 h* ^3 I; H
6 o) C5 A& U0 k8 u. F; l- G- d
I might write a managed port, if someone’s interested. All feedback’s welcome. |