108 lines
2.8 KiB
C++
108 lines
2.8 KiB
C++
#include <Windows.h>
|
|
#include <random>
|
|
#include "Window.h"
|
|
#include "Direct3D.h"
|
|
#include "Mesh.h"
|
|
#include "Material.h"
|
|
#include "Camera.h"
|
|
#include "Time.h"
|
|
#include "Light.h"
|
|
#include "Utilities.h"
|
|
|
|
int WINAPI WinMain(
|
|
HINSTANCE hInstance, // handle to instance of application
|
|
HINSTANCE hPrevInstance, // deprecated
|
|
PSTR szCmdLine, // command line
|
|
int nCmdShow // how should the window be opened (minimized, maximized or normal)
|
|
)
|
|
{
|
|
// some constant values
|
|
const UINT width = 640;
|
|
const UINT height = 480;
|
|
const BOOL isFullscreen = FALSE;
|
|
const BYTE red = 255;
|
|
const BYTE green = 255;
|
|
const BYTE blue = 255;
|
|
|
|
UINT error = 0; // error code for identifying errors
|
|
|
|
// 1. create window
|
|
Window window = {};
|
|
error = window.init(hInstance, width, height);
|
|
CheckError(error);
|
|
|
|
// 2. create connection to Direct3D
|
|
Direct3D d3d = {};
|
|
error = d3d.init(window.getWindowHandle(), width, height, isFullscreen);
|
|
CheckError(error);
|
|
|
|
// set render states
|
|
d3d.getDevice()->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
|
|
d3d.getDevice()->SetRenderState(D3DRS_LIGHTING, FALSE);
|
|
|
|
// 3. create a mesh
|
|
Mesh mesh = {};
|
|
error = mesh.init(d3d.getDevice());
|
|
CheckError(error);
|
|
|
|
// 4. create a camera
|
|
Camera camera = {};
|
|
error = camera.init(width, height);
|
|
CheckError(error);
|
|
|
|
// 5. create time
|
|
Time time = {};
|
|
error = time.init();
|
|
CheckError(error);
|
|
|
|
// 6. create a material
|
|
Material material = {};
|
|
error = material.init(d3d.getDevice(), TEXT("wall.jpg"));
|
|
CheckError(error);
|
|
|
|
// 7. create light source
|
|
Light light = {};
|
|
error = light.init();
|
|
CheckError(error);
|
|
|
|
// 8. run application
|
|
while (window.run())
|
|
{
|
|
if (GetAsyncKeyState(VK_F1) & 0x8000) d3d.getDevice()->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);
|
|
if (GetAsyncKeyState(VK_F2) & 0x8000) d3d.getDevice()->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
|
|
if (GetAsyncKeyState(VK_F3) & 0x8000) d3d.getDevice()->SetRenderState(D3DRS_FILLMODE, D3DFILL_POINT);
|
|
if (GetAsyncKeyState(VK_F4) & 0x8000) d3d.getDevice()->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
|
|
if (GetAsyncKeyState(VK_F5) & 0x8000) d3d.getDevice()->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW);
|
|
if (GetAsyncKeyState(VK_F6) & 0x8000) d3d.getDevice()->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
|
|
|
|
// 8.1. update objects
|
|
time.update();
|
|
mesh.update(time.getDeltaTime());
|
|
camera.update(time.getDeltaTime(), d3d.getDevice());
|
|
light.update(time.getDeltaTime());
|
|
|
|
// 8.2. render objects
|
|
static std::default_random_engine e;
|
|
static std::uniform_int_distribution<int> d(0, 255);
|
|
|
|
//d3d.beginScene(d(e), d(e), d(e)); //random color
|
|
d3d.beginScene(red, green, blue);
|
|
|
|
light.render(d3d.getDevice());
|
|
material.render(d3d.getDevice());
|
|
mesh.render(d3d.getDevice());
|
|
|
|
d3d.endScene();
|
|
}
|
|
|
|
// 9. tidy up
|
|
light.deInit();
|
|
time.deInit();
|
|
camera.deInit();
|
|
material.deInit();
|
|
mesh.deInit();
|
|
d3d.deInit();
|
|
window.deInit();
|
|
|
|
return 0;
|
|
} |