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
|
#include <Windows.h>
#include <TriBase.h>
#include "..\\..\\Allgemeines\\InitWindow.h"
#include "..\\..\\Allgemeines\\Direct3DEnum.h"
#include "..\\..\\Allgemeines\\InitDirect3D.h"
#include "Resource.h"
#include "D3D9.h"
#pragma comment(lib, "d3dx9.lib")
struct SVertex{
tbVector3 vPosition;
DWORD dwColor;
};
SVertex TriangleVertex[3];
SDirect3DParameters D3DP;
float fTime = 0.0f;
tbResult Render(float fNumSecsPassed){
tbMatrix mRotation(tbMatrixRotationY(TB_DEG_TO_RAD(fTime * 90.0f)));
tbMatrix mTranslation(tbMatrixTranslation(tbVector3(2.0f,0.0f,0.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->DrawPrimitiveUP(D3DPT_TRIANGLELIST,
1,
TriangleVertex,
sizeof(SVertex));
g_pD3DDevice->EndScene();
g_pD3DDevice->Present(NULL,NULL,NULL,NULL);
return TB_OK;
}
tbResult Move(float fNumSecsPassed){
fTime += fNumSecsPassed;
return TB_OK;
}
tbResult InitScene(){
g_pD3DDevice->SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE);
g_pD3DDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
g_pD3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
g_pD3DDevice->SetRenderState(D3DRS_DITHERENABLE, TRUE);
float Aspect = (float)(D3DP.VideoMode.Width) / (float)(D3DP.VideoMode.Height);
tbMatrix mProjection = tbMatrixProjection(TB_DEG_TO_RAD(90.0f),
Aspect,
0.1f,
100.0f);
g_pD3DDevice->SetTransform(D3DTS_PROJECTION,(D3DMATRIX*)(&mProjection));
TriangleVertex[0].vPosition = tbVector3(1.0f,0.0f,0.0f);
TriangleVertex[1].vPosition = tbVector3(1.0f,-1.0f,0.0f);
TriangleVertex[2].vPosition = tbVector3(-1.0f,-1.0f,0.0f);
TriangleVertex[0].dwColor = tbColor(0.0f,1.0f,0.0f);
TriangleVertex[1].dwColor = tbColor(1.0f,1.0f,0.0f);
TriangleVertex[2].dwColor = tbColor(1.0f,1.0f,0.0f);
return TB_OK;
}
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE PrevInstance,
char* pcCommandLine,
int iShowCommand){
tbInit();
tbResult Result = GetDirect3DParameters(&D3DP);
if(Result == TB_CANCELED){
tbExit();
return 0;
}
InitScene();
HRESULT hResult;
if(FAILED(hResult = InitWindow(D3DP.VideoMode.Width,
D3DP.VideoMode.Height,
"Das Spiel",
LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1)))))
{
MessageBox(g_hWindow,"Fehler beim Initialisieren des Fensters","Fehler",MB_OK | MB_ICONEXCLAMATION);
return 1;
tbExit();
}
if(FAILED(hResult = InitDirect3D(&D3DP, g_hWindow)))
{
MessageBox(g_hWindow,"Fehler beim Initialisieren des Fensters","Fehler",MB_OK | MB_ICONEXCLAMATION);
}
tbDoMessageLoop(Render,Move);
ExitDirect3D();
ExitWindow();
tbExit();
return 0;
}
|