用于在全屏游戏上画东西,写字。- G9 Q- Z( c+ v* X
, B' V5 }: k( k5 _4 J原文
5 o3 |9 m- ]% R# ] shttp://www.gamedev.net/community/forums/topic.asp?topic_id=3593196 J% u) F9 N* s$ Y/ i
# W" x* s" Z! Y$ A3 AA 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.
+ j8 y" p+ D$ J% {/ L
! s- z- ?: _" }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.3 G7 v( B8 N1 g" S1 e
1 M: [7 D6 X3 t! U: b) PBack to the sample. The files of interest are:
1 H* j& I0 s" {& O4 XOverlay.cpp: Window creation (auto-generated, nothing interesting) and the main loop (important).
2 z" M, a* r: s1 [overlay_renderer.h, overlay_renderer.cpp: The core of the sample. The code is fairly self-explanatory, though.
2 J/ E4 A8 |' U# l/ t
% _& k4 p+ M/ y g( \4 }$ C* oOne 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:
# I8 p4 j0 l9 b: ~8 `! U; tdwAlignBoundarySrc
* B& n. S: H LdwAlignSizeSrc
& j5 k$ c( @0 ZdwAlignBoundaryDest4 T7 l. c; c, g' y% t3 u
dwAlignSizeDest& e# S: R& }) E" j9 ~
dwAlignStrideAlign
" _; b( n( h0 @6 n3 p$ \: K1 G$ YdwMinOverlayStretch
4 \' n3 X3 Z% N. k; w+ O( vdwMaxOverlayStretch3 z2 Q6 m! w2 d2 a
6 d+ W. h$ ~% Q: 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.( U+ B1 Z7 o+ A% m* v# A: D; _
' w' d4 M/ D/ g; v+ uThe limitations (and overlays in general) are documented under “DirectDraw->DirectDraw Essentials->Surfaces->Overlay Surfaces” in the DX7 documentation. It’s available at icarusIndie.
" W! b/ y2 b4 h9 t7 V c9 T& w2 M" j5 ^; b( Q3 {% Y- T
I might write a managed port, if someone’s interested. All feedback’s welcome. |