Hi there,

I started working on a new 3D engine and tried to eliminate Omega directX . So far I tried to render some random trianges with no result. The code was ported from my old engine (Necro3D), but it doesn't seem to work. I thing I'm missing some stuff in the creation of the device or in the Device.SetTransform?? I checked the vertex buffer, that is created correctly, (and filled) but when I render I don't see anything... The "camera" is set at pos (0, 0, 0), triangles are randomly spawn around it, so I should see some stuff on screen, but the screen keeps it nice background color from Device.Clear...

anyway, here is my code (I'm no b00b in DX, but im stuck with this for 2 day now ) It uses Clootie's D3D headers, code is from a test program I, to it crashes when you close it.

[pascal]
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Math,

D3DX9, Direct3D9;


type
TFVF = record
x, y, z: single;
nx, ny, nz: single;
Color: DWord;
u, v: single;
end;

TForm1 = class(TForm)
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
public
D3D : IDirect3D9;
Device : IDirect3DDevice9;

vb : IDirect3DVertexBuffer9;
procedure Init;
procedure CreateVB;
procedure SetTransform;
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.CreateVB;
var Size: integer;
i: Integer;
p_vb: array of TFVF;
x: Integer;
begin
Size := (SizeOf(TFVF)*3) * 100;
if Failed(Device.CreateVertexBuffer(Size,
D3DUSAGE_WRITEONLY,
D3DFVF_XYZ or D3DFVF_NORMAL or D3DFVF_DIFFUSE or D3DFVF_TEX1,
D3DPOOL_MANAGED,
vb, nil)) then
begin
ShowMessage('Error @ Device.CreateVertexBuffer');
Exit;
end;

ShowMessage(IntTostr(Size));
vb.Lock(0, Size, Pointer(p_vb), 0);

Randomize;
for i := 0 to 99 do
begin
for x := 0 to 3 do
begin

p_vb[i*3 + x].x := Random(100)-50;
p_vb[i*3 + x].y := Random(100)-50;
p_vb[i*3 + x].z := Random(100)-50;

p_vb[i*3 + x].nx := 0.0;
p_vb[i*3 + x].ny := 0.0;
p_vb[i*3 + x].nz := 0.0;

p_vb[i*3 + x].Color := $FFFFFFFF;
p_vb[i*3 + x].u := 0;
p_vb[i*3 + x].u := 1;

end;
end;

vb.Unlock;

end;

procedure TForm1.FormShow(Sender: TObject);
begin
Init;
CreateVB;
Timer1.Enabled := True;
end;

procedure TForm1.Init;
var d3dpp : TD3DPresentParameters;
DevType : _D3DDEVTYPE;
BehaviorFlags : DWord;
begin
D3D := Direct3DCreate9( D3D_SDK_VERSION);
if D3D=nil then
begin
ShowMessage('Error @ D3D := Direct3DCreate9( D3D_SDK_VERSION);');
Exit;
end;

ZeroMemory(@d3dpp, SizeOf(d3dpp));
d3dpp.Windowed := True;
d3dpp.SwapEffect := D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat := D3DFMT_X8R8G8B8;
d3dpp.BackBufferWidth := 800;
d3dpp.BackBufferHeight := 600;
d3dpp.BackBufferCount := 1;
d3dpp.PresentationInterval := D3DPRESENT_INTERVAL_IMMEDIATE;
d3dpp.FullScreen_RefreshRateInHz := 0;


d3dpp.MultiSampleType := D3DMULTISAMPLE_NONE;
d3dpp.EnableAutoDepthStencil := True;
d3dpp.AutoDepthStencilFormat := D3DFMT_D24S8; // 16-bit z-Buffer



d3dpp.Flags := D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL;



if Failed( D3D.CreateDevice( D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
Handle,
D3DCREATE_HARDWARE_VERTEXPROCESSING,
@d3dpp, Device) ) then
begin
ShowMessage('Error@ D3D.CreateDevice');
Exit;
end;

end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
Device.Clear(0, nil, D3DCLEAR_TARGET or D3DCLEAR_ZBUFFER, $00DDDD, 1, 0);

// Begin the scene
if Failed(Device.BeginScene) then
begin
SetTransform;


Device.SetFVF(D3DFVF_XYZ or D3DFVF_NORMAL or D3DFVF_DIFFUSE or D3DFVF_TEX1);
Device.SetStreamSource(0, vb, 0, SizeOf(TFVF));

Device.DrawPrimitive(D3DPT_TRIANGLELIST, 0, 10);
end;

Device.EndScene;
Device.Present(nil, nil, Handle, nil);
end;

procedure TForm1.SetTransform;
var matProj, matWorld, matView, matRot, matPos: TD3DXMatrix;
Quat : TD3DXQuaternion;

matScale, xx : TD3DMatrix;
begin

// Projection
D3DXMatrixPerspectiveFovLH( matProj, DegToRad(90), 800/600, 1, 1000000);
Device.SetTransform(D3DTS_PROJECTION, matProj);

// View
D3DXQuaternionRotationYawPitchRoll(Quat, 0, 0, 0);
D3DXMatrixRotationQuaternion( matRot, Quat );
D3DXMatrixTranslation(matPos, 0, 0, 0);
D3DXMatrixMultiply(matView, matRot, matPos);
D3DXMatrixInverse( matView, nil, matView );
Device.SetTransform(D3DTS_VIEW, matView);

// World (sorry for the xx)
D3DXMatrixRotationYawPitchRoll(matRot, 0, 0, 0);
D3DXMatrixTranslation(matPos, 0, 0, 0);
D3DXMatrixScaling(matScale, 1, 1, 1);
D3DXMatrixMultiply(xx, matRot, matPos);
D3DXMatrixMultiply(xx, matScale, xx);
Device.SetTransform(D3DTS_WORLD, xx);
end;


end.

[/pascal]