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
|
#include <iostream>
#include <Windows.h>
#include <D3D10.h>
#include "TriBase.h"
#include "tbVector3.h"
#include "tbMatrix.h"
#include "tbPlane.h"
#include "InitWindow.h"
#include "Direct3DEnum.h"
#include "InitDirect3D.h"
float g_fTime=0;struct SVertex
{
tbVector3 vPosition;
DWORD dwColor;
};
SVertex g_aDreieckVertex [3];
tbResult InitScene()
{
HRESULT hResult;if (FAILED(hResult = g_pD3DDevice->SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE)))
{TB_ERROR_DIRECTX("g_pD3DDevice->SetFVF", hResult, TB_ERROR);
}
g_pD3DDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
g_pD3DDevice->SetRenderState(D3DRS_CULLMODE, FALSE);
g_pD3DDevice->SetRenderState(D3DRS_DITHERENABLE,TRUE);return TB_OK;
}tbResult Render (float NumSecsPassed)
{
HRESULT hResult;
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));if(FAILED(hResult = g_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 63), 1.0f, 0)))
{TB_ERROR_DIRECTX("d_pD3DDevice->clear", hResult, TB_STOP);
}
g_pD3DDevice->BeginScene();if(FAILED(hResult = g_pD3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 1, g_aDreieckVertex, sizeof (SVertex))))
{TB_ERROR_DIRECTX("g_pD3DDevice->Draw", hResult, TB_STOP);
}
g_pD3DDevice->EndScene();
g_pD3DDevice->Present(NULL ,NULL, NULL, NULL);
return TB_OK;
}tbResult Move (float NumSecsPassed)
{
g_fTime += NumSecsPassed;return TB_OK;
}int WINAPI WinMain (HINSTANCE hInstance,
HINSTANCE hPrevInstance,char*pcCmdLine,int iShowCmd)
{
tbInit ();
SDirect3DParameters Direct3DParameters;
tbResult Result = GetDirect3DParameters(&Direct3DParameters);if (Result == TB_ERROR)
{MessageBox (NULL, "Es ist ein fehler aufgetreten!", "Fehler!", MB_OK | MB_ICONWARNING);
tbExit ();return 1;
}else if (Result == TB_CANCELED)
{
tbExit ();return 0;
}if(InitWindow(Direct3DParameters.VideoMode.Width,
Direct3DParameters.VideoMode.Height,"Programm",
NULL))
{MessageBox (NULL, "es ist ein fehler aufgetreten!", "Fehler", MB_OK | MB_ICONWARNING);
tbExit ();return 1;
}if(InitDirect3D(&Direct3DParameters,
g_hWindow))
{MessageBox(NULL, "Es ist ein Fehler aufgetreten!", "Fehler!", MB_OK | MB_ICONWARNING);
tbExit ();return 1;
}float fAspect = (float)(Direct3DParameters.VideoMode.Width)/(float)(Direct3DParameters.VideoMode.Height);
tbMatrix mProjection = tbMatrixProjection(TB_DEG_TO_RAD(90.0f),
fAspect,
0.1,
100.0f);
g_aDreieckVertex[0].vPosition = tbVector3(0.0f, 1.0f, 0.0f);
g_aDreieckVertex[1].vPosition = tbVector3(1.0f, -1.0f, 0.0f);
g_aDreieckVertex[2].vPosition = tbVector3(-1.0f, -1.0f, 0.0f);
g_aDreieckVertex[0].dwColor = tbColor(1.0f, 0.0f, 0.0f);
g_aDreieckVertex[0].dwColor = tbColor(0.0f, 1.0f, 0.0f);
g_aDreieckVertex[0].dwColor = tbColor(0.0f, 0.0f, 1.0f);
tbDoMessageLoop (Render, Move);
ExitDirect3D ();
ExitWindow ();
tbExit();return 0;
}
|