用于在全屏游戏上画东西,写字。7 s9 ~) c% t* L7 r
' B- M' K I- ]1 ^; s原文1 a% j. a+ t; l' M B
http://www.gamedev.net/community/forums/topic.asp?topic_id=359319! f% p, k3 I5 f7 U* a L
: _- A: A% e2 b. N
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.
$ p' f, R7 ]5 `& N) u6 t) `7 Q3 G! p6 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.
: K/ n! }% Z1 b, F5 R4 }9 r9 Y6 L2 d4 m+ M3 i8 d
Back to the sample. The files of interest are:
( ?; H8 D( q# ~Overlay.cpp: Window creation (auto-generated, nothing interesting) and the main loop (important).4 P n7 X0 `, b; m; c2 X0 Q: B
overlay_renderer.h, overlay_renderer.cpp: The core of the sample. The code is fairly self-explanatory, though.8 @9 j5 P7 j" ~2 I8 U' B5 X
* w2 P3 C' n* H/ V; T* W, y! TOne 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:
5 B) x% {# |" {" \* R2 A/ Z, LdwAlignBoundarySrc+ _ [2 m. a( z- D
dwAlignSizeSrc$ ?/ B' ` O* {+ F' F u9 E
dwAlignBoundaryDest. |. y: u5 |0 {9 N
dwAlignSizeDest
) t: T# ^3 t8 f9 @# SdwAlignStrideAlign 9 {9 O/ r2 N$ v: B: B) a
dwMinOverlayStretch
2 u2 ~& }- k5 O7 ]7 rdwMaxOverlayStretch" Q9 W( V1 p8 ?/ T% a
4 z" P) a5 _% ~6 l1 o+ S: xThe 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./ Y/ s6 Q# g( i
- f4 L6 I0 R- m5 a; B6 R5 U
The limitations (and overlays in general) are documented under “DirectDraw->DirectDraw Essentials->Surfaces->Overlay Surfaces” in the DX7 documentation. It’s available at icarusIndie.& M: `9 w3 [0 v! A/ @; l7 d
, U9 N8 ]. P+ Q# o
I might write a managed port, if someone’s interested. All feedback’s welcome. |