181 lines
5.3 KiB
C
181 lines
5.3 KiB
C
#pragma once
|
|
|
|
#pragma data_seg(".screenQuad")
|
|
struct ScreenQuadVertex { float x, y, z, w, u, v; };
|
|
ScreenQuadVertex screenQuad[] = {
|
|
{width, height, 0, 1, 1, 1},
|
|
{-1, height, 0, 1, 0, 1},
|
|
{width, -1, 0, 1, 1, 0},
|
|
{-1, -1, 0, 1, 0, 0}
|
|
};
|
|
|
|
#pragma data_seg(".d3dPresParams")
|
|
D3DPRESENT_PARAMETERS d3dPresParams = {
|
|
width,
|
|
height,
|
|
D3DFMT_A8R8G8B8,
|
|
1,
|
|
D3DMULTISAMPLE_4_SAMPLES,
|
|
0,
|
|
D3DSWAPEFFECT_DISCARD,
|
|
0,
|
|
false,
|
|
true,
|
|
D3DFMT_D16,
|
|
0,
|
|
D3DPRESENT_RATE_DEFAULT,
|
|
D3DPRESENT_INTERVAL_ONE
|
|
};
|
|
|
|
#pragma code_seg(".InitTexts")
|
|
__forceinline void InitTexts()
|
|
{
|
|
hDc = ::GetDC(hWnd);
|
|
::SelectObject(hDc, CreateFontA(0, 0, 0, 0, FW_BOLD, false, false, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH|FF_DONTCARE, "wingdings"));
|
|
for (int i = 0; i < textAmount; ++i)
|
|
D3DXCreateTextA(d3dDevice, hDc, (LPCSTR)texts[i], 0.0f, 0.1f, &textMeshes[i], NULL, NULL);
|
|
}
|
|
|
|
#pragma code_seg(".InitGraphics")
|
|
inline void InitGraphics()
|
|
{
|
|
d3dPresParams.hDeviceWindow = hWnd;
|
|
#ifdef _DEBUG
|
|
d3dPresParams.Windowed = true;
|
|
#endif
|
|
Direct3DCreate9(D3D_SDK_VERSION)->CreateDevice(0, D3DDEVTYPE_HAL, hWnd, D3DCREATE_MIXED_VERTEXPROCESSING, &d3dPresParams, &d3dDevice);
|
|
|
|
for (int i = 0; i < shaderAmount; ++i)
|
|
{
|
|
D3DXCompileShader(shader, shaderLength, 0, 0, shaderEntryPoint, shaderProfiles[i], 0, &shaderBuffer, &errorBuffer, 0);
|
|
(*shaderEntryPoint)++;
|
|
|
|
#ifndef TARGET_4K
|
|
if (errorBuffer->GetBufferSize() != 0)
|
|
OutputDebugStringA((LPCSTR)errorBuffer->GetBufferPointer());
|
|
#endif
|
|
|
|
void* bufferPointer = shaderBuffer->GetBufferPointer();
|
|
if (shaderCreationFunctionsDevice[i]) _asm
|
|
{
|
|
MOV ebx, DWORD ptr [i]
|
|
MOV eax, DWORD ptr [d3dDevice]
|
|
MOV eax, DWORD ptr [eax]
|
|
MOV ecx, DWORD ptr shaderTargets[ebx*4]
|
|
PUSH ecx
|
|
MOV ecx, DWORD ptr shaderCreationFunctions[ebx*4]
|
|
PUSH DWORD ptr [bufferPointer]
|
|
PUSH DWORD ptr [d3dDevice]
|
|
MOV eax, DWORD ptr [eax+ecx]
|
|
CALL eax
|
|
}
|
|
else
|
|
D3DXCreateTextureShader((DWORD*)bufferPointer, (LPD3DXTEXTURESHADER*)shaderTargets[i]);
|
|
}
|
|
|
|
D3DXCreateSphere(d3dDevice, 1, 64, 64, &meshes[0], NULL);
|
|
D3DXCreateBox(d3dDevice, 1, 1, 1, &meshes[1], NULL);
|
|
D3DXCreateCylinder(d3dDevice, 1, 1, 1, 32, 1, &meshes[2], NULL);
|
|
D3DXCreateTorus(d3dDevice, 0.5f, 1, 4, 4, &meshes[3], NULL);
|
|
D3DXCreateTorus(d3dDevice, 0.25f, 1, 4, 4, &meshes[4], NULL);
|
|
D3DXCreateTeapot(d3dDevice, &meshes[5], NULL);
|
|
D3DXCreateMatrixStack(0, &matrixStack);
|
|
|
|
InitTexts();
|
|
|
|
d3dDevice->CreateTexture(width, height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &blurRenderTexture, NULL);
|
|
d3dDevice->CreateTexture(width, height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &renderTexture, NULL);
|
|
|
|
d3dDevice->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
|
|
d3dDevice->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
|
|
|
|
blurRenderTexture->GetSurfaceLevel(0, &blurRenderSurface);
|
|
renderTexture->GetSurfaceLevel(0, &renderSurface);
|
|
d3dDevice->GetRenderTarget(0, &bufferSurface);
|
|
|
|
d3dDevice->Present(NULL, NULL, NULL, NULL);
|
|
}
|
|
|
|
#pragma code_seg(".UpdateMatrices")
|
|
void UpdateMatrices()
|
|
{
|
|
_asm
|
|
{
|
|
push 44800000h
|
|
push 3E000000h
|
|
push 3FAA0000h
|
|
push 3F490000h
|
|
push offset projectionMatrix
|
|
push offset rotationAxis+0Ch
|
|
push offset rotationAxis+24h
|
|
push offset viewPosition
|
|
push offset viewMatrix
|
|
call DWORD ptr[D3DXMatrixLookAtLH]
|
|
call dword ptr [D3DXMatrixPerspectiveFovLH]
|
|
|
|
mov eax,dword ptr [d3dDevice]
|
|
mov esi,dword ptr [eax]
|
|
push 4
|
|
push offset viewProjectionMatrix
|
|
push 4
|
|
push eax
|
|
push 4
|
|
push offset viewMatrix
|
|
push 0
|
|
push eax
|
|
push offset projectionMatrix
|
|
push offset viewMatrix
|
|
push offset viewProjectionMatrix
|
|
push offset viewMatrix
|
|
mov eax,dword ptr [matrixStack]
|
|
push eax
|
|
mov eax,dword ptr [eax]
|
|
call dword ptr [eax+44h]
|
|
push eax
|
|
push offset viewMatrix
|
|
call dword ptr [D3DXMatrixMultiply]
|
|
call dword ptr [D3DXMatrixMultiply]
|
|
call dword ptr [esi+178h]
|
|
call dword ptr [esi+178h]
|
|
}
|
|
}
|
|
|
|
#pragma code_seg(".DrawFrame")
|
|
inline void DrawFrame()
|
|
{
|
|
d3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DXCOLOR(0.0f, 0.0f, 0.0f, 0.5f), 1.0f, 0);
|
|
d3dDevice->BeginScene();
|
|
|
|
d3dDevice->SetVertexShader(vertexShader);
|
|
d3dDevice->SetPixelShader(lightShader);
|
|
d3dDevice->SetVertexShaderConstantF(9, identityVectors[0], 1);
|
|
|
|
//matrixStack->LoadIdentity();
|
|
RunVM();
|
|
|
|
//GLOW
|
|
d3dDevice->SetTexture(0, blurRenderTexture);
|
|
d3dDevice->SetTexture(1, renderTexture);
|
|
|
|
d3dDevice->SetFVF(D3DFVF_XYZRHW | D3DFVF_TEX1);
|
|
|
|
d3dDevice->StretchRect(bufferSurface, NULL, blurRenderSurface, NULL, D3DTEXF_LINEAR);
|
|
d3dDevice->StretchRect(bufferSurface, NULL, renderSurface, NULL, D3DTEXF_LINEAR);
|
|
|
|
d3dDevice->SetPixelShader(blurShader);
|
|
|
|
int i = 4;
|
|
do
|
|
{
|
|
d3dDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, screenQuad, sizeof(ScreenQuadVertex));
|
|
d3dDevice->StretchRect(bufferSurface, NULL, blurRenderSurface, NULL, D3DTEXF_LINEAR);
|
|
} while (--i);
|
|
|
|
d3dDevice->SetPixelShader(combineShader);
|
|
d3dDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, screenQuad, sizeof(ScreenQuadVertex));
|
|
// END GLOW
|
|
|
|
d3dDevice->EndScene();
|
|
d3dDevice->Present(NULL, NULL, NULL, NULL);
|
|
}
|