用于在全屏游戏上画东西,写字。5 {0 t5 W( M, E' _$ a7 Y
$ |" G; y3 z& Y
原文
2 N0 c4 s: k% ]4 m" rhttp://www.gamedev.net/community/forums/topic.asp?topic_id=359319 w1 R8 J' m7 f1 N) e: g
8 a" ]& E& n: J( f! e6 Y
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.
+ u6 R- {* ?* J: ?, e+ \# D% o4 N( @1 q5 t6 y& c9 }3 m# S
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.% r/ x6 w1 h5 Z, ~( s
, y. \! E# F8 eBack to the sample. The files of interest are:/ D) J( s; \" Q# Z, |- E
Overlay.cpp: Window creation (auto-generated, nothing interesting) and the main loop (important).& E) w' F0 v2 Y* H) c( q
overlay_renderer.h, overlay_renderer.cpp: The core of the sample. The code is fairly self-explanatory, though.
/ w4 k/ J0 V5 l2 ?1 E4 n8 `: _) y' _, w( j% r# [
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:
; `& D- V' M5 xdwAlignBoundarySrc6 p4 ~7 j5 s& ]4 { U( o
dwAlignSizeSrc
2 P% o# M6 t* d3 Y1 a2 g3 s; n$ FdwAlignBoundaryDest
% J$ N1 f3 D; xdwAlignSizeDest
5 y7 E1 w1 U2 R4 ~% P4 X8 CdwAlignStrideAlign
. Z5 J: m6 _5 B" hdwMinOverlayStretch . |5 S: K# C9 X# p
dwMaxOverlayStretch
- a( Z6 l4 w+ k5 {* d& m
# K, W) D: F' uThe 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.5 N- N' t/ s3 P
! S( q, h# w. ~0 e# d, XThe limitations (and overlays in general) are documented under “DirectDraw->DirectDraw Essentials->Surfaces->Overlay Surfaces” in the DX7 documentation. It’s available at icarusIndie.
- E- G/ n, b( N# V6 v# U0 y
2 g- d3 N9 y. h' BI might write a managed port, if someone’s interested. All feedback’s welcome. |