用于在全屏游戏上画东西,写字。
W- R/ A2 K( z- N6 D- Q9 n6 `# M7 R/ X C( F: Q
原文
2 W R5 k5 y. B0 A4 jhttp://www.gamedev.net/community/forums/topic.asp?topic_id=359319
; Z/ h: P% `! a. h0 Q
# o m) N0 |- M ?: d+ E/ kA 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.
* a3 q: f! }- b* u1 @. [- D' p; G, f$ R$ Q& ~2 O& I! G2 t
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.% ]( V7 S4 G' e1 B( B- N3 x
" J! F4 y7 a' {- s
Back to the sample. The files of interest are:
, Y+ i( h+ v5 mOverlay.cpp: Window creation (auto-generated, nothing interesting) and the main loop (important).
# Q: L( D, ^3 [9 `. s2 z: r6 Uoverlay_renderer.h, overlay_renderer.cpp: The core of the sample. The code is fairly self-explanatory, though.
( W2 u! Z8 l8 g( z2 n
8 r, D* x0 d: x5 _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:- r1 y4 E! y3 F# J
dwAlignBoundarySrc
' o1 W& S" ?& Q1 m7 O4 v: hdwAlignSizeSrc3 B8 {; a7 k! g8 n- V1 L3 }
dwAlignBoundaryDest
7 b& [/ Z* q+ A/ p, zdwAlignSizeDest
\" N; C1 n9 A9 ^1 O; D) NdwAlignStrideAlign 7 o: L& y5 L F e2 a7 y" v
dwMinOverlayStretch + @8 I/ G+ ?2 ]% b
dwMaxOverlayStretch
+ q. }7 S) H& W- _2 Q9 \2 e1 ]3 [6 y( O" R9 z- e1 K6 a% j3 K6 ~
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.
- e% R' |* s: h; q5 U' D8 g& i- P8 P
The limitations (and overlays in general) are documented under “DirectDraw->DirectDraw Essentials->Surfaces->Overlay Surfaces” in the DX7 documentation. It’s available at icarusIndie.. W8 T& _+ N& z5 S
6 R7 e% V1 u3 ~% h7 P
I might write a managed port, if someone’s interested. All feedback’s welcome. |