用于在全屏游戏上画东西,写字。' u0 s, e3 Z' ?- e
' f* ~' r* L, s# f5 @
原文
" H6 e! _$ m7 \4 e; Bhttp://www.gamedev.net/community/forums/topic.asp?topic_id=359319
- ^ t8 f* L' ^, y/ `
: i8 D& F/ Z" ]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., e! H# W/ ~: m6 x8 ?) l2 W
, n4 Y0 w; l( l7 H" o& _2 F
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.9 }1 u8 \) N' X
! S2 J( O( T2 | t# [
Back to the sample. The files of interest are:2 d% m) f8 f& d/ T Q: T8 O
Overlay.cpp: Window creation (auto-generated, nothing interesting) and the main loop (important).
0 \" B$ G9 \: roverlay_renderer.h, overlay_renderer.cpp: The core of the sample. The code is fairly self-explanatory, though.! f- |2 h M7 P: Q# g5 y) L d
1 } q7 Y) D$ r" {. x% J7 U* 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:8 m" d; I) |: o/ E2 D
dwAlignBoundarySrc
; X& v/ m3 O8 F0 a' G% @& n5 udwAlignSizeSrc4 ]% s3 J* ]/ a, _8 x2 f
dwAlignBoundaryDest
+ w& I8 U* n4 j" gdwAlignSizeDest; s# B# K. A8 M9 ^+ z+ ] j
dwAlignStrideAlign
, c" R% o B, N% @# _$ n5 C/ z! l/ ldwMinOverlayStretch 9 ?2 {$ X4 g/ l; X/ G- C8 m
dwMaxOverlayStretch3 b6 a- O+ y* K
3 f1 {+ v! b5 L+ R
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.( C/ \, m- g- b( {6 O
( k3 ~$ v6 z; V! G, o e8 q! }The limitations (and overlays in general) are documented under “DirectDraw->DirectDraw Essentials->Surfaces->Overlay Surfaces” in the DX7 documentation. It’s available at icarusIndie.8 G7 ]6 N/ k& }' ~7 f+ @# h
* t+ C7 d1 Z2 a: H9 lI might write a managed port, if someone’s interested. All feedback’s welcome. |