-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcpic.cpp
93 lines (61 loc) · 1.6 KB
/
cpic.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "cpic.h"
HRESULT CPic::Init(LPDIRECT3DDEVICE9 g_pd3dDevice, LPCWSTR picpath, int width, int height)
{
HRESULT hr;
//get device
m_pd3dDevice = g_pd3dDevice;
//sprite initalize
hr = D3DXCreateTextureFromFileEx(
m_pd3dDevice,
picpath,
height,
width,
D3DX_DEFAULT,
D3DUSAGE_DYNAMIC,
D3DFMT_UNKNOWN,
D3DPOOL_DEFAULT,
D3DX_DEFAULT,
D3DX_DEFAULT,
0, //D3DCOLOR_COLORVALUE(0,0,0,1),
&img_info,
NULL,
&tex
);
char string[256];
sprintf(string, "...Created texture: %s, %dx%d\n", picpath, (int)img_info.Width, (int)img_info.Height);
LogPlease(string);
if(FAILED(hr)) return hr;
hr = D3DXCreateSprite(
m_pd3dDevice,
&spr);
if(FAILED(hr)) return hr;
return S_OK;
}
HRESULT CPic::Render(RECT *Rect, D3DXVECTOR2 *pScaling, D3DXVECTOR3 *pRotationCenter, FLOAT Rotation, D3DXVECTOR3 *pTranslation, BOOL bAlpha)
{
//render
spr->Begin( D3DXSPRITE_ALPHABLEND );
m_pd3dDevice->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA);
m_pd3dDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);
if(bAlpha) m_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);
D3DXMATRIX mat;
D3DXMatrixScaling( &mat, pScaling->x, pScaling->y, 1);
spr->SetTransform( &mat );
spr->Draw(tex,
Rect,
pRotationCenter,
pTranslation,
D3DCOLOR_RGBA(255,255,255,255)
);
m_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);
spr->End();
return S_OK;
}
HRESULT CPic::Release()
{
tex->Release();
spr->Release();
return S_OK;
}
//--------------------------------------------------------
//--------------------------------------------------------