-
Notifications
You must be signed in to change notification settings - Fork 0
/
Quad.cpp
89 lines (74 loc) · 2.16 KB
/
Quad.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
89
#include "Quad.h"
Quad::Quad()
{
pTexture = NULL;
}
Quad::~Quad()
{
SAFE_RELEASE(pTexture);
}
HRESULT Quad::Load(char* fileName)
{
//「テクスチャオブジェクト」の作成
if (FAILED(D3DXCreateTextureFromFileEx(g_pDevice, fileName, 0, 0, 0, 0, D3DFMT_UNKNOWN,
D3DPOOL_DEFAULT, D3DX_FILTER_NONE, D3DX_DEFAULT, NULL, NULL, NULL, &pTexture)))
{
MessageBox(0, "テクスチャの作成に失敗しました", fileName, MB_OK);
return E_FAIL;
}
}
HRESULT Quad::Draw(D3DXMATRIX* matWorld, D3DXMATRIX* matTex)
{
struct Vertex
{
D3DXVECTOR3 pos;
DWORD color;
D3DXVECTOR2 uv;
};
Vertex point[] =
{
D3DXVECTOR3(-0.5, 0.5, 0), D3DCOLOR_ARGB(255, 255, 255, 255), D3DXVECTOR2(0,0), //左上
D3DXVECTOR3(0.5, 0.5, 0), D3DCOLOR_ARGB(255, 255, 255, 255), D3DXVECTOR2(1,0), //右上
D3DXVECTOR3(-0.5, -0.5, 0), D3DCOLOR_ARGB(255, 255, 255, 255), D3DXVECTOR2(0, 1), //左下
D3DXVECTOR3(0.5, -0.5, 0), D3DCOLOR_ARGB(255, 255, 255, 255), D3DXVECTOR2(1, 1) //右下
};
if (FAILED(g_pDevice->SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1)))
{
MessageBox(0, "頂点ストリームの設定に失敗しました", "Line", MB_OK);
return E_FAIL;
}
if (FAILED(g_pDevice->SetTransform(D3DTS_WORLD, matWorld)))
{
MessageBox(0, "ワールド行列の設定に失敗しました", "Quad", MB_OK);
return E_FAIL;
}
if (FAILED(g_pDevice->SetTexture(0, pTexture)))
{
MessageBox(0, "テクスチャのセットに失敗しました", "Quad", MB_OK);
return E_FAIL;
}
if (matTex != NULL)
{
if (FAILED(g_pDevice->SetTransform(D3DTS_TEXTURE0, matTex)))
{
MessageBox(0, "テクスチャ行列の設定に失敗しました", "Quad", MB_OK);
return E_FAIL;
}
}
if (FAILED(g_pDevice->SetRenderState(D3DRS_LIGHTING, FALSE)))
{
MessageBox(0, "ライトの設定に失敗しました", "Quad", MB_OK);
return E_FAIL;
}
if (FAILED(g_pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, point, sizeof(Vertex))))
{
MessageBox(0, "ポリゴンの描画に失敗しました", "Quad", MB_OK);
return E_FAIL;
}
if (FAILED(g_pDevice->SetRenderState(D3DRS_LIGHTING, TRUE)))
{
MessageBox(0, "ライトの設定に失敗しました", "Quad", MB_OK);
return E_FAIL;
}
return S_OK;
}