program WIN32GUI 'DX9Sample';
#include 'user32.zir';
#include 'kernel32.zir';
#include 'messages.zir';
#include 'colors.zir';
#include 'directx/direct3d9.zir';
//////////////////////////////
//directx globals
D3DPRESENT_PARAMETERS presParams;
/////////
//other variables
tagWndClassA wndClass;
tagMsg msg;
DWord hInstance = GetModuleHandleA(nil);
//
//handles
DWord hMainFRM;
//
//////////////////////////////
function WindowProc(DWord hWnd; DWord uMsg; DWord wParam; DWord lParam) {
if (uMsg == WM_COMMAND) {
eax = DefWindowProcA(hWnd, uMsg, wParam, lParam);
ret
} elseif (uMsg == WM_DESTROY) {
PostQuitMessage(0);
} else {
eax = DefWindowProcA(hWnd, uMsg, wParam, lParam);
}
}
const className = 'ZMainFRM';
wndClass.hbrBackground = COLOR_BACKGROUND;
wndClass.hInstance = hInstance;
wndClass.lpszClassName = className;
wndClass.lpfnWndProc = @WindowProc;
RegisterClassA(@wndClass);
hMainFRM = CreateWindowExA(0, className, 'Ziron DirectX9 Demo', WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 1024, 768, 0, 0, hInstance, nil);
ShowWindow(hMainFRM, SW_SHOWNORMAL);
presParams.hDeviceWindow = hMainFRM;
presParams.Windowed = True;
presParams.BackBufferWidth = 1024;
presParams.BackBufferHeight = 768;
presParams.BackBufferCount = 1;
presParams.BackBufferFormat = D3DFMT_A8R8G8B8;
presParams.SwapEffect = D3DSWAPEFFECT_DISCARD;
presParams.AutoDepthStencilFormat = D3DFMT_D24X8;
presParams.EnableAutoDepthStencil = True;
IDirect3DDevice9 dx_device;
IDirect3D9 dx_object = Direct3DCreate9(D3D_SDK_VERSION);
edi = dx_object;
eax = edi.CreateDevice(0, D3DDEVTYPE_HAL, hMainFRM, 64, @presParams, @dx_device);
//edi as nothing;
edi = dx_device;
push esi;
esi = 0xFF000000;
// Set up message loop
while (eax <> WM_QUIT) {
edi.clear(0, nil, 3, esi, 1.0, 0);
edi.BeginScene;
//
//render something here :)
//
edi.EndScene;
edi.Present(nil, nil, 0, nil);
add esi, 0x512
eax = PeekMessage(@msg, 0, 0, 0, 1);
if (eax) {
TranslateMessage(@msg);
DispatchMessageA(@msg);
eax = msg.message;
}
}
edi as nothing;
pop esi
ExitProcess(0);