Register | Login
Forum Index > Samples > Ziron DirectX9 Sample
Author Message
Pages: 1
Admin
Site Admin

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[73] Ziron DirectX9 Sample - posted: 2011-10-08 21:40:43
This sample shows the basics of getting started with DirectX9, creating a window, initializing directx and running the render/message loop.

This code will assemble with the upcoming release Ziron 1.1.21.8 at only 3kb in size!

Code:
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);


Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
Pages: 1
create new reply


Quick reply:

Message:



Currently Active Users:
There are currently 4 user(s) online. 0 member(s) and 4 guest(s)
Most users ever online was 1046, January 28, 2022, 2:08 pm.


Statistics:
Threads: 225 | Posts: 1848 | Members: 51 | Active Members: 51
Welcome to our newest member, yecate
const Copyright = '2011-2024 © OverHertz Ltd. All rights reserved.';
Web development by OverHertz Ltd