/[cvs]/api/include/d3dxsprite.h
ViewVC logotype

Annotation of /api/include/d3dxsprite.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (hide annotations) (vendor branch)
Sun Jul 1 20:47:59 2001 UTC (23 years, 4 months ago) by bearsoft
Branch: lazy, MAIN
CVS Tags: start, HEAD
Changes since 1.1: +0 -0 lines
File MIME type: text/plain
First import

1 bearsoft 1.1 ///////////////////////////////////////////////////////////////////////////
2     //
3     // Copyright (C) 1999 Microsoft Corporation. All Rights Reserved.
4     //
5     // File: d3dxsprite.h
6     // Content: D3DX sprite helper functions
7     //
8     // These functions allow you to use sprites with D3DX. A "sprite" is
9     // loosely defined as a 2D image that you want to transfer to the
10     // rendering target. The source image can be a texture created
11     // with the help of the D3DX texture loader; though advanced users may
12     // want to create their own. A helper function (PrepareDeviceForSprite)
13     // is provided to make it easy to set up render states on a device.
14     // (Again, advanced users can use their own created devices.)
15     //
16     // There are two general techniques for sprites; the simpler one just
17     // specifies a destination rectangle and a rotation anlge. A more
18     // powerful technique supports rendering to non-rectangular quads.
19     //
20     // Both techniques support clipping, alpha, and rotation. More
21     // details are below.
22     //
23     ///////////////////////////////////////////////////////////////////////////
24    
25     #ifndef __D3DXSPRITE_H__
26     #define __D3DXSPRITE_H__
27    
28     #include <d3d.h>
29     #include <limits.h>
30     #include "d3dxerr.h"
31    
32     #ifdef __cplusplus
33     extern "C" {
34     #endif
35    
36    
37     //-------------------------------------------------------------------------
38     // D3DXPrepareDeviceForSprite:
39     //
40     // Call this function to set up all the render states necessary for
41     // BltSprite/WarpSprite to work correctly. (Advanced users may opt to
42     // not call this function first; in which case Blt/WarpSprite functions
43     // will use whatever render/texture states were set up on the device when
44     // they are called.)
45     //
46     // Warning: This function modifies render states and may impact performance
47     // negatively on some 3D hardware if it is called too often per frame.
48     //
49     // Warning: If the render state changes (other than through calls to
50     // BltSprite or WarpSprite), you will need to call this function again before
51     // calling BltSprite or WarpSprite.
52     //
53     // Details: This function modifies the the rendering first texture stage and
54     // it modifies some renderstates for the entire device. Here is the exact
55     // list:
56     //
57     // SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
58     // SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
59     // SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
60     // SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
61     // SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
62     // SetTextureStageState(0, D3DTSS_MINFILTER, D3DTFN_LINEAR);
63     // SetTextureStageState(0, D3DTSS_MAGFILTER, D3DTFG_LINEAR);
64     //
65     // SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
66     // SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA);
67     // SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
68     //
69     // Depending on the value of ZEnable parameter, this function will
70     // will either call
71     // SetRenderState(D3DRENDERSTATE_ZENABLE, FALSE);
72     // - or -
73     // SetRenderState(D3DRENDERSTATE_ZENABLE, TRUE);
74     //
75     // Parameters:
76     // pd3dDevice - a pointer to the d3d device that you wish to prepare
77     // for use with D3DX Sprite Services
78     // ZEnable - a flag indicating whether you want the sprites to
79     // check and update the Z buffer as part of rendering.
80     // If ZEnable is FALSE, OR you are using
81     // alpha-blending, then it is necessary to render your
82     // sprites from back-to-front.
83     //
84     //-------------------------------------------------------------------------
85    
86     #ifdef __cplusplus
87     HRESULT WINAPI
88     D3DXPrepareDeviceForSprite( LPDIRECT3DDEVICE7 pd3dDevice,
89     BOOL ZEnable = FALSE);
90     #else
91     HRESULT WINAPI
92     D3DXPrepareDeviceForSprite( LPDIRECT3DDEVICE7 pd3dDevice,
93     BOOL ZEnable);
94     #endif
95    
96    
97    
98     //-------------------------------------------------------------------------
99     // The D3DXDrawBasicSprite() function performs blitting of source images onto
100     // a 3D rendering device. This function only calls SetTexture on the first
101     // renderstage with the parameter (pd3dTexture) if that parameter is non-null.
102     // This function assumes that D3DXPrepareDeviceForSprite has been called on
103     // the device or that caller has in some other way correctly prepared the
104     // renderstates.
105     //
106     // This function supports scaling, rotations, alpha-blending, and choosing
107     // a source sub-rect.
108     //
109     // Rotation angle is specified in radians. Both rotations and scales
110     // are applied around the center of the sprite; where the center of the
111     // sprite is half the width/height of the sprite, plus the offset parameter.
112     //
113     // Use the offset parameter if you want the sprite's center to be something
114     // other than the image center.
115     //
116     // The destination point indicates where you would like the center of
117     // the sprite to draw to.
118     //
119     // Parameters:
120     // pd3dTexture - a pointer to the surface containing the texture
121     // pd3dDevice - a pointer to the d3d device to render to. It is
122     // assumed that render states are set up. (See
123     // D3DXPrepareDeviceForSprite)
124     // ppointDest - a pointer to the target point for the sprite. The
125     // components of the vector must be in screen
126     // space.
127     // alpha - alpha value to apply to sprite. 1.0 means totally
128     // opaque; and 0.0 means totally transparent.
129     // WARNING: If you are using alpha, then you should render
130     // from back to front in order to avoid rendering
131     // artifacts.
132     // angleRad - angle of rotation around the 'center' of the rect
133     // scale - a uniform scale that is applied to the source rect
134     // to specify the size of the image that is rendered
135     // pOffset - offset from the center of the source rect to use as the
136     // center of rotation
137     // pSourceRect - a rect that indicates what portion of the source
138     // source texture to use. If NULL is passed, then the
139     // entire source is used. If the source texture was
140     // created via D3DX, then the rect should be specified
141     // in the coordinates of the original image (so that you
142     // don't have to worry about stretching/scaling that D3DX
143     // may have done to make the image work with your current
144     // 3D Device.) Note that horizontal or vertical mirroring
145     // may be simply accomplished by swapping the left/right
146     // or top/bottom fields of this RECT.
147     //-------------------------------------------------------------------------
148    
149     #ifdef __cplusplus
150     HRESULT WINAPI
151     D3DXDrawSpriteSimple(LPDIRECTDRAWSURFACE7 pd3dTexture,
152     LPDIRECT3DDEVICE7 pd3dDevice,
153     const D3DXVECTOR3 *ppointDest,
154     float alpha = 1.0f,
155     float scale = 1.0f,
156     float angleRad = 0.0f,
157     const D3DXVECTOR2 *pOffset = NULL,
158     const RECT *pSourceRect = NULL);
159     #else
160     HRESULT WINAPI
161     D3DXDrawSpriteSimple(LPDIRECTDRAWSURFACE7 pd3dTexture,
162     LPDIRECT3DDEVICE7 pd3dDevice,
163     D3DXVECTOR3 *ppointDest,
164     float alpha,
165     float scale,
166     float angleRad,
167     D3DXVECTOR2 *pOffset,
168     RECT *pSourceRect);
169     #endif
170    
171     //-------------------------------------------------------------------------
172     // The D3DXDrawSprite() function transforms source images onto a 3D
173     // rendering device. It takes a general 4x4 matrix which is use to transform
174     // the points of a default rect: (left=-.5, top=-.5, right=+.5, bottom=+.5).
175     // (This default rect was chosen so that it was centered around the origin
176     // to ease setting up rotations. And it was chosen to have a width/height of one
177     // to ease setting up scales.)
178     //
179     // This function only calls SetTexture on the first
180     // renderstage with the parameter (pd3dTexture) if that parameter is non-null.
181     // This function assumes that D3DXPrepareDeviceForSprite has been called on
182     // the device or that caller has in some other way correctly prepared the
183     // renderstates.
184     //
185     // This function supports alpha-blending, and choosing
186     // a source sub-rect. (A value of NULL for source sub-rect means the entire
187     // texture is used.)
188     //
189     // Note that if the transformed points have a value for w (the homogenous
190     // coordinate) that is not 1, then this function will invert it and pass
191     // that value to D3D as the rhw field of a TLVERTEX. If the value for w is
192     // zero, then it use 1 as the rhw.
193     //
194     // Parameters:
195     // pd3dTexture - a pointer to the surface containing the texture
196     // pd3dDevice - a pointer to the d3d device to render to. It is
197     // assumed that render states are set up. (See
198     // D3DXPrepareDeviceForSprite)
199     // pMatrixTransform - 4x4 matrix that specifies the transformation
200     // that will be applied to the default -.5 to +.5
201     // rectangle.
202     // alpha - alpha value to apply to sprite. 1.0 means totally
203     // opaque; and 0.0 means totally transparent.
204     // WARNING: If you are using alpha, then you should render
205     // from back to front in order to avoid rendering
206     // artifacts.Furthermore, you should avoid scenarios where
207     // semi-transparent objects intersect.
208     // pSourceRect - a rect that indicates what portion of the source
209     // source texture to use. If NULL is passed, then the
210     // entire source is used. If the source texture was
211     // created via D3DX, then the rect should be specified
212     // in the coordinates of the original image (so that you
213     // don't have to worry about stretching/scaling that D3DX
214     // may have done to make the image work with your current
215     // 3D Device.) Note that mirroring may be simply accomplished
216     // by swapping the left/right or top/bottom fields of
217     // this RECT.
218     //
219     //-------------------------------------------------------------------------
220    
221     #ifdef __cplusplus
222     HRESULT WINAPI
223     D3DXDrawSpriteTransform(LPDIRECTDRAWSURFACE7 pd3dTexture,
224     LPDIRECT3DDEVICE7 pd3dDevice,
225     const D3DXMATRIX *pMatrixTransform,
226     float alpha = 1.0f,
227     const RECT *pSourceRect = NULL);
228     #else
229     HRESULT WINAPI
230     D3DXDrawSpriteTransform(LPDIRECTDRAWSURFACE7 pd3dTexture,
231     LPDIRECT3DDEVICE7 pd3dDevice,
232     D3DXMATRIX *pMatrixTransform,
233     float alpha,
234     RECT *pSourceRect);
235     #endif
236    
237     //-------------------------------------------------------------------------
238     // The D3DXBuildSpriteTransform() function is a helper provided which
239     // creates a matrix corresponding to simple properties. This matrix is
240     // set up to pass directly to D3DXTransformSprite.
241     //
242     // Parameters:
243     // pMatrix - a pointer to the result matrix
244     // prectDest - a pointer to the target rectangle for the sprite
245     // angleRad - angle of rotation around the 'center' of the rect
246     // pOffset - offset from the center of the source rect to use as the
247     // center of rotation
248     //
249     //-------------------------------------------------------------------------
250    
251     #ifdef __cplusplus
252     void WINAPI
253     D3DXBuildSpriteTransform(D3DXMATRIX *pMatrix,
254     const RECT *prectDest,
255     float angleRad = 0.0f,
256     const D3DXVECTOR2 *pOffset = NULL);
257     #else
258     void WINAPI
259     D3DXBuildSpriteTransform(D3DXMATRIX *pMatrix,
260     RECT *prectDest,
261     float angleRad,
262     D3DXVECTOR2 *pOffset);
263     #endif
264    
265    
266     //-------------------------------------------------------------------------
267     // The D3DXDrawSprite3D() function renders a texture onto a 3D quad. The
268     // quad ABCD is broken into two triangles ABC and ACD which are rendered
269     // via DrawPrim.
270     //
271     // Parameters:
272     // pd3dTexture - a pointer to the surface containing the texture
273     // pd3dDevice - a pointer to the d3d device to render to. It is
274     // assumed that render states are set up. (See
275     // D3DXPrepareDeviceForSprite)
276     // quad - array of 4 points in the following order:
277     // upper-left, upper-right, lower-right, lower-left.
278     // If these vectors contain a W, then this function
279     // will take the reciprocal of that value to pass as
280     // as the rhw (i.e. reciprocal homogenous w).
281     // alpha - alpha value to apply to sprite. 1.0 means totally
282     // opaque; and 0.0 means totally transparent.
283     // WARNING: If you are using alpha, then you should render
284     // from back to front in order to avoid rendering
285     // artifacts.Furthermore, you should avoid scenarios where
286     // semi-transparent objects intersect.
287     // pSourceRect - a rect that indicates what portion of the source
288     // source texture to use. If NULL is passed, then the
289     // entire source is used. If the source texture was
290     // created via D3DX, then the rect should be specified
291     // in the coordinates of the original image (so that you
292     // don't have to worry about stretching/scaling that D3DX
293     // may have done to make the image work with your current
294     // 3D Device.) Note that mirroring may be simply accomplished
295     // by swapping the left/right or top/bottom fields of
296     // this RECT.
297     //-------------------------------------------------------------------------
298    
299     #ifdef __cplusplus
300     HRESULT WINAPI
301     D3DXDrawSprite3D(LPDIRECTDRAWSURFACE7 pd3dTexture,
302     LPDIRECT3DDEVICE7 pd3dDevice,
303     const D3DXVECTOR4 quad[4],
304     float alpha = 1.0f,
305     const RECT *pSourceRect = NULL);
306     #else
307     HRESULT WINAPI
308     D3DXDrawSprite3D(LPDIRECTDRAWSURFACE7 pd3dTexture,
309     LPDIRECT3DDEVICE7 pd3dDevice,
310     D3DXVECTOR4 quad[4],
311     float alpha,
312     RECT *pSourceRect);
313     #endif
314    
315    
316    
317     #ifdef __cplusplus
318     } // extern "C"
319     #endif
320    
321     #endif // __D3DXSPRITE_H__

root@recompile.se
ViewVC Help
Powered by ViewVC 1.1.26