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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
#include <windows.h>
#include <tribase.h>
#include "Direct3DEnum.h"
#include "InitWindow.h"
#include "InitDirect3D.h"
// GLOBALS
struct SVertex
{
tbVector3 pos;
DWORD col;
};
// Das Flexible Vertex Format
const DWORD FVF = D3DFVF_XYZ | D3DFVF_DIFFUSE;
SVertex g_Triangle[3];
PDIRECT3DVERTEXBUFFER9 g_pVertexBuffer = NULL;
float g_fTime = 0.0f;
// PROTOTYPEN
int Game_Init();
int Game_Exit();
tbResult Render(float);
tbResult Move(float);
int Scene_Init();
// Start des Codes
int Game_Init()
{
tbInit();
SDirect3DParameters *param = new SDirect3DParameters();
GetDirect3DParameters(param);
InitWindow(param->VideoMode.Width, param->VideoMode.Height, "VBuffer", LoadIcon(NULL, IDI_APPLICATION));
InitDirect3D(param, g_hWindow);
Scene_Init();
float fAspect = float(param->VideoMode.Width) / float(param->VideoMode.Height);
tbMatrix mProjection = tbMatrixProjection(TB_DEG_TO_RAD(90.0f),
fAspect,
0.1f,
100.0f);
g_pD3DDevice->SetTransform(D3DTS_PROJECTION, (D3DMATRIX*)&mProjection);
return 0;
}
int Game_Exit()
{
g_pVertexBuffer = NULL;
ExitDirect3D();
ExitWindow();
tbExit();
return 0;
}
int Scene_Init()
{
g_pD3DDevice->SetFVF(FVF);
g_pD3DDevice->SetRenderState(D3DRS_LIGHTING, false);
g_pD3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
g_pD3DDevice->SetRenderState(D3DRS_DITHERENABLE, true);
g_pD3DDevice->CreateVertexBuffer(sizeof(SVertex) * 3, D3DUSAGE_WRITEONLY, FVF,
D3DPOOL_DEFAULT, &g_pVertexBuffer, NULL);
g_pVertexBuffer->Lock(0, 0, (void**)&g_Triangle[0], NULL);
g_Triangle[0].pos = tbVector3(0.0f, 1.0f, 0.0f);
g_Triangle[0].col = tbColor(1.0f,0.0f,0.0f);
g_Triangle[1].pos = tbVector3(1.0f,-1.0f, 0.0f);
g_Triangle[1].col = tbColor(0.0f,1.0f,0.0f);
g_Triangle[2].pos = tbVector3(-1.0f,-1.0f, 0.0f);
g_Triangle[2].col = tbColor(0.0f,0.0f,1.0f);
g_pVertexBuffer->Unlock();
return 0;
}
tbResult Render(float fNumSecsPassed)
{
tbMatrix mRotation = tbMatrixRotationY(TB_DEG_TO_RAD(g_fTime * 90.0f));
tbMatrix mTranslation = tbMatrixTranslation(tbVector3(0.0f,0.0f,2.0f));
tbMatrix mWorld = (mRotation * mTranslation);
g_pD3DDevice->SetTransform(D3DTS_WORLD, (D3DMATRIX*)&mWorld);
g_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 63), 1.0f, 0);
g_pD3DDevice->BeginScene();
g_pD3DDevice->SetStreamSource(0, g_pVertexBuffer, 0, sizeof(SVertex));
g_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);
g_pD3DDevice->EndScene();
g_pD3DDevice->Present(NULL, NULL, NULL, NULL);
return TB_OK;
}
tbResult Move(float fNumSecsPassed)
{
g_fTime += fNumSecsPassed;
return TB_OK;
}
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShowCmd)
{
Game_Init();
tbDoMessageLoop(Render, Move);
Game_Exit();
return 0;
}
|