Compare commits
3 Commits
24c7faad4d
...
98804d9ee4
| Author | SHA1 | Date | |
|---|---|---|---|
| 98804d9ee4 | |||
| 7862a974fc | |||
| 6e7c61c705 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -6,3 +6,4 @@
|
||||
*.idb
|
||||
*.obj
|
||||
*.res
|
||||
*.aps
|
||||
10
build.bat
10
build.bat
@ -1,15 +1,23 @@
|
||||
fxc /Od /Zi /T fx_4_0 /nologo /Fo main.fxo main.fx
|
||||
|
||||
@if %errorlevel% neq 0 exit /b %errorlevel%
|
||||
|
||||
rem build main resource
|
||||
rc.exe /d "_UNICODE" /d "UNICODE" /fo"Debug\main.res" ".\main.rc"
|
||||
|
||||
@if %errorlevel% neq 0 exit /b %errorlevel%
|
||||
|
||||
rem compile
|
||||
cl.exe @"compile.rsp" "main.cpp"
|
||||
|
||||
@if %errorlevel% neq 0 exit /b %errorlevel%
|
||||
|
||||
rem link
|
||||
link.exe @"link.rsp" /NOLOGO /ERRORREPORT:PROMPT
|
||||
|
||||
mt.exe -manifest d3d10.exe.manifest -outputresource:Debug\d3d10.exe;1
|
||||
@if %errorlevel% neq 0 exit /b %errorlevel%
|
||||
|
||||
mt.exe -manifest d3d10.exe.debug.manifest -outputresource:Debug\d3d10.exe;1
|
||||
|
||||
@if %errorlevel% neq 0 exit /b %errorlevel%
|
||||
|
||||
|
||||
24
build_release.bat
Normal file
24
build_release.bat
Normal file
@ -0,0 +1,24 @@
|
||||
fxc /Od /Zi /T fx_4_0 /nologo /Fo main.fxo main.fx
|
||||
|
||||
@if %errorlevel% neq 0 exit /b %errorlevel%
|
||||
|
||||
rem build main resource
|
||||
rc.exe /d "_UNICODE" /d "UNICODE" /fo"Release\main.res" ".\main.rc"
|
||||
|
||||
@if %errorlevel% neq 0 exit /b %errorlevel%
|
||||
|
||||
rem compile
|
||||
cl.exe @"compile_release.rsp" "main.cpp"
|
||||
|
||||
@if %errorlevel% neq 0 exit /b %errorlevel%
|
||||
|
||||
rem link
|
||||
link.exe @"link_release.rsp" /NOLOGO /ERRORREPORT:PROMPT
|
||||
|
||||
@if %errorlevel% neq 0 exit /b %errorlevel%
|
||||
|
||||
mt.exe -manifest d3d10.exe.release.manifest -outputresource:Release\d3d10.exe;1
|
||||
|
||||
@if %errorlevel% neq 0 exit /b %errorlevel%
|
||||
|
||||
Release\d3d10.exe
|
||||
19
compile_release.rsp
Normal file
19
compile_release.rsp
Normal file
@ -0,0 +1,19 @@
|
||||
/O2
|
||||
/GL
|
||||
/D "WIN32"
|
||||
/D "NDEBUG"
|
||||
/D "_WINDOWS"
|
||||
/D "_UNICODE"
|
||||
/D "UNICODE"
|
||||
/FD
|
||||
/EHsc
|
||||
/MT
|
||||
/Fo"Release\\"
|
||||
/Fd"Release\vc80.pdb"
|
||||
/W3
|
||||
/c
|
||||
/Wp64
|
||||
/Zi
|
||||
/TP
|
||||
/nologo
|
||||
/errorReport:prompt
|
||||
25
link_release.rsp
Normal file
25
link_release.rsp
Normal file
@ -0,0 +1,25 @@
|
||||
/INCREMENTAL:NO
|
||||
/SUBSYSTEM:WINDOWS
|
||||
/OPT:REF
|
||||
/OPT:ICF
|
||||
/LTCG
|
||||
/MANIFEST:NO
|
||||
/MACHINE:X86
|
||||
/OUT:"Release\d3d10.exe"
|
||||
/PDB:"Release\d3d10.pdb"
|
||||
d3d10.lib
|
||||
d3dx10.lib
|
||||
kernel32.lib
|
||||
user32.lib
|
||||
gdi32.lib
|
||||
winspool.lib
|
||||
comdlg32.lib
|
||||
advapi32.lib
|
||||
shell32.lib
|
||||
ole32.lib
|
||||
oleaut32.lib
|
||||
uuid.lib
|
||||
odbc32.lib
|
||||
odbccp32.lib
|
||||
".\Release\main.obj"
|
||||
".\Release\main.res"
|
||||
86
main.cpp
86
main.cpp
@ -8,7 +8,9 @@ HINSTANCE g_hInstance = NULL;
|
||||
HWND g_hWnd = NULL;
|
||||
ID3D10Device * g_pd3dDevice = NULL;
|
||||
IDXGISwapChain * g_pSwapChain = NULL;
|
||||
ID3D10Texture2D * g_pDepthStencil = NULL;
|
||||
ID3D10RenderTargetView * g_pRenderTargetView = NULL;
|
||||
ID3D10DepthStencilView * g_pDepthStencilView = NULL;
|
||||
ID3D10Effect * g_pEffect = NULL;
|
||||
ID3D10EffectTechnique * g_pTechnique = NULL;
|
||||
ID3D10InputLayout * g_pVertexLayout = NULL;
|
||||
@ -18,7 +20,8 @@ ID3D10Buffer * g_pIndexBuffer = NULL;
|
||||
ID3D10EffectMatrixVariable * g_pWorldVariable = NULL;
|
||||
ID3D10EffectMatrixVariable * g_pViewVariable = NULL;
|
||||
ID3D10EffectMatrixVariable * g_pProjectionVariable = NULL;
|
||||
D3DXMATRIX g_World;
|
||||
D3DXMATRIX g_World1;
|
||||
D3DXMATRIX g_World2;
|
||||
D3DXMATRIX g_View;
|
||||
D3DXMATRIX g_Projection;
|
||||
|
||||
@ -150,8 +153,8 @@ HRESULT InitDirect3DDevice()
|
||||
|
||||
DXGI_SWAP_CHAIN_DESC sd = {};
|
||||
sd.BufferCount = 1;
|
||||
sd.BufferDesc.Width = 640;
|
||||
sd.BufferDesc.Height = 480;
|
||||
sd.BufferDesc.Width = width;
|
||||
sd.BufferDesc.Height = height;
|
||||
sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
sd.BufferDesc.RefreshRate.Numerator = 60;
|
||||
sd.BufferDesc.RefreshRate.Denominator = 1;
|
||||
@ -189,6 +192,7 @@ HRESULT InitDirect3DDevice()
|
||||
}
|
||||
print("driverType %d\n", driverType);
|
||||
|
||||
// back buffer
|
||||
ID3D10Texture2D * pBackBuffer;
|
||||
hr = g_pSwapChain->GetBuffer(0, __uuidof(ID3D10Texture2D), (LPVOID *)&pBackBuffer);
|
||||
if (FAILED(hr)) {
|
||||
@ -202,12 +206,37 @@ HRESULT InitDirect3DDevice()
|
||||
return hr;
|
||||
}
|
||||
|
||||
g_pd3dDevice->OMSetRenderTargets(1, &g_pRenderTargetView, NULL);
|
||||
// depth buffer
|
||||
D3D10_TEXTURE2D_DESC descDepth;
|
||||
descDepth.Width = width;
|
||||
descDepth.Height = height;
|
||||
descDepth.MipLevels = 1;
|
||||
descDepth.ArraySize = 1;
|
||||
descDepth.Format = DXGI_FORMAT_D32_FLOAT;
|
||||
descDepth.SampleDesc.Count = 1;
|
||||
descDepth.SampleDesc.Quality = 0;
|
||||
descDepth.Usage = D3D10_USAGE_DEFAULT;
|
||||
descDepth.BindFlags = D3D10_BIND_DEPTH_STENCIL;
|
||||
descDepth.CPUAccessFlags = 0;
|
||||
descDepth.MiscFlags = 0;
|
||||
hr = g_pd3dDevice->CreateTexture2D(&descDepth, NULL, &g_pDepthStencil);
|
||||
if (FAILED(hr))
|
||||
return hr;
|
||||
|
||||
D3D10_DEPTH_STENCIL_VIEW_DESC descDSV;
|
||||
descDSV.Format = descDepth.Format;
|
||||
descDSV.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D;
|
||||
descDSV.Texture2D.MipSlice = 0;
|
||||
hr = g_pd3dDevice->CreateDepthStencilView(g_pDepthStencil, &descDSV, &g_pDepthStencilView);
|
||||
if (FAILED(hr))
|
||||
return hr;
|
||||
|
||||
g_pd3dDevice->OMSetRenderTargets(1, &g_pRenderTargetView, g_pDepthStencilView);
|
||||
|
||||
// viewport
|
||||
D3D10_VIEWPORT vp;
|
||||
vp.Width = 640;
|
||||
vp.Height = 480;
|
||||
vp.Width = width;
|
||||
vp.Height = height;
|
||||
vp.MinDepth = 0.0f;
|
||||
vp.MaxDepth = 1.0f;
|
||||
vp.TopLeftX = 0;
|
||||
@ -233,7 +262,7 @@ HRESULT InitDirect3DDevice()
|
||||
&pBlobErrors,
|
||||
NULL);
|
||||
if (FAILED(hr)) {
|
||||
print("D3DX10CreateEffectFromFile\n");
|
||||
print("D3DX10CreateEffectFromResource\n");
|
||||
if (pBlobErrors != NULL) {
|
||||
const char * pError = (const char *)pBlobErrors->GetBufferPointer();
|
||||
print("pError: %p\n", pError);
|
||||
@ -336,7 +365,8 @@ HRESULT InitDirect3DDevice()
|
||||
g_pd3dDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
|
||||
|
||||
// transform matrices
|
||||
D3DXMatrixIdentity(&g_World);
|
||||
D3DXMatrixIdentity(&g_World1);
|
||||
D3DXMatrixIdentity(&g_World2);
|
||||
|
||||
D3DXVECTOR3 Eye(0.0f, 2.0f, -5.0f);
|
||||
D3DXVECTOR3 At(0.0f, 1.0f, 0.0f);
|
||||
@ -359,21 +389,55 @@ HRESULT InitDirect3DDevice()
|
||||
void Render()
|
||||
{
|
||||
static float t = 0.0f;
|
||||
if (0) {
|
||||
t += (float)D3DX_PI * 0.0125f;
|
||||
D3DXMatrixRotationY(&g_World, t);
|
||||
} else {
|
||||
static DWORD dwTimeStart = 0;
|
||||
DWORD dwTimeCur = GetTickCount();
|
||||
if (dwTimeStart == 0)
|
||||
dwTimeStart = dwTimeCur;
|
||||
t = (dwTimeCur - dwTimeStart) / 1000.0f;
|
||||
}
|
||||
|
||||
// first cube
|
||||
D3DXMatrixRotationY(&g_World1, t);
|
||||
|
||||
// second cube
|
||||
D3DXMATRIX mTranslate;
|
||||
D3DXMATRIX mOrbit;
|
||||
D3DXMATRIX mSpin;
|
||||
D3DXMATRIX mScale;
|
||||
D3DXMatrixRotationZ(&mSpin, -t);
|
||||
D3DXMatrixRotationY(&mOrbit, -t * 2.0f);
|
||||
D3DXMatrixTranslation(&mTranslate, -4.0f, 0.0f, 0.0f);
|
||||
D3DXMatrixScaling(&mScale, 0.3f, 0.3f, 0.3f);
|
||||
|
||||
D3DXMatrixMultiply(&g_World2, &mScale, &mSpin);
|
||||
D3DXMatrixMultiply(&g_World2, &g_World2, &mTranslate);
|
||||
D3DXMatrixMultiply(&g_World2, &g_World2, &mOrbit);
|
||||
|
||||
|
||||
float ClearColor[4] = { 0.0f, 0.125f, 0.6f, 1.0f };
|
||||
g_pd3dDevice->ClearRenderTargetView(g_pRenderTargetView, ClearColor);
|
||||
g_pd3dDevice->ClearDepthStencilView(g_pDepthStencilView, D3D10_CLEAR_DEPTH, 1.0f, 0);
|
||||
|
||||
g_pWorldVariable->SetMatrix((float *)&g_World);
|
||||
g_pViewVariable->SetMatrix((float *)&g_View);
|
||||
g_pProjectionVariable->SetMatrix((float *)&g_Projection);
|
||||
|
||||
D3D10_TECHNIQUE_DESC techDesc;
|
||||
g_pTechnique->GetDesc(&techDesc);
|
||||
|
||||
// render first cube
|
||||
g_pWorldVariable->SetMatrix((float *)&g_World1);
|
||||
for(UINT p = 0; p < techDesc.Passes; p++) {
|
||||
g_pTechnique->GetPassByIndex(p)->Apply(0);
|
||||
g_pd3dDevice->DrawIndexed(36, 0, 0);
|
||||
}
|
||||
|
||||
// render second cube
|
||||
g_pWorldVariable->SetMatrix((float *)&g_World2);
|
||||
for(UINT p = 0; p < techDesc.Passes; p++) {
|
||||
g_pTechnique->GetPassByIndex(p)->Apply(0);
|
||||
//g_pd3dDevice->Draw(3, 0);
|
||||
g_pd3dDevice->DrawIndexed(36, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user