Results 1 to 3 of 3

Thread: Arrg, It was there before...

  1. #1

    Arrg, It was there before...

    ello,

    I'm having trouble with getting some triangels to draw... l started following the http://www.drunkenhyena.com tuts and ran into a problem.

    When I got to tut2, ie the addtion of 3D space, my triangle stoped being drawn.

    [pascal]
    type
    TDXTestF = class(TForm)
    DXTimer: TTimer;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure DXTimerTimer(Sender: TObject);
    private
    { Private declarations }
    public
    { Public declarations }
    end;

    TMyVertex = packed record
    x, y, z{, w}: Single;
    Colour: TD3DColor;
    end;

    var
    DXTestF: TDXTestF;
    g_D3D : IDirect3D8 = nil;
    g_d3d_device : IDirect3DDevice8 = nil;
    g_Tri : array [0..2] of TMyVertex = ((x : 0; y : 1; z : 0;{ w : 2; }Colour : $ffffffff),
    (x : 1; y : -1; z : 0;{ w : 2;} Colour : $0000ff00),
    (x : -1; y : -1; z : 0;{ w : 2; }Colour : $000000ff));

    implementation

    {$R *.dfm}

    procedure TDXTestF.FormCreate(Sender: TObject);
    var d3dpp : D3DPRESENT_PARAMETERS;
    display_mode : D3DDISPLAYMODE;
    view_matrix : TD3DXMATRIX;
    matProj : TD3DXMATRIX;
    tmp1, tmp2 : single;
    vEyePt, vLookatPt, vUpVec: TD3DXVector3;
    begin
    g_D3D := Direct3DCreate8( D3D_SDK_VERSION );
    if(g_D3D = nil) then
    begin
    showmessage('Error getting Direct3D');
    exit;
    end;

    if(FAILED(g_D3D.GetAdapterDisplayMode(D3DADAPTER_D EFAULT,display_mode)))then
    begin
    showmessage('Error getting display mode');
    exit;
    end;

    ZeroMemory(@d3dpp,sizeof(d3dpp));

    d3dpp.SwapEffect := D3DSWAPEFFECT_DISCARD;
    d3dpp.hDeviceWindow := DXTestF.Handle;
    d3dpp.BackBufferCount:= 1;

    d3dpp.Windowed := TRUE;
    d3dpp.BackBufferFormat := display_mode.Format;

    if(FAILED(g_D3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, DXTestF.Handle,
    D3DCREATE_SOFTWARE_VERTEXPROCESSING, d3dpp, g_d3d_device)))then
    begin
    showmessage('Error createing device');
    exit;
    end;

    vEyePt := D3DXVector3( 0.0, 0.0, -8.0 );
    vLookatPt := D3DXVector3( 1.0, 1.0, 1.0 );
    vUpVec := D3DXVector3( 0.0, 1.0, 0.0 );

    D3DXMatrixLookAtLH(view_matrix, vEyePt,
    vLookatPt,
    vUpVec);

    g_d3d_device.SetTransform(D3DTS_VIEW,view_matrix);

    tmp1 := D3DX_PI/4;
    tmp2 := DXTestF.Width / DXTestF.Height;

    D3DXMatrixPerspectiveFovLH(matProj, tmp1, tmp2, 0.1, 100.0 );

    g_d3d_device.SetTransform( D3DTS_PROJECTION, matProj );

    DXTimer.Enabled := true;
    end;

    procedure TDXTestF.FormDestroy(Sender: TObject);
    begin
    DXTimer.Enabled := false;

    g_d3d_device := nil;

    g_D3D := nil;
    end;

    procedure TDXTestF.DXTimerTimer(Sender: TObject);
    var matWorld : TD3DXMATRIX;
    begin
    g_d3d_device.BeginScene;

    g_d3d_device.Clear(0, nil, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1, 0);

    g_d3d_device.SetVertexShader(D3DFVF_XYZ or D3DFVF_DIFFUSE);

    D3DXMatrixTranslation(matWorld, 0.0, 0.0, 0.0);
    g_d3d_device.SetTransform(D3DTS_WORLD, matWorld);

    g_d3d_device.DrawPrimitiveUP(D3DPT_TRIANGLELIST, 1, g_Tri, sizeof(TMyVertex));

    g_d3d_device.EndScene;

    g_d3d_device.Present(nil,nil,0,nil);
    end;
    [/pascal]

    can somone tell me why??

    Thanks, Armand.

  2. #2

    So, show up again!

    It seems you forgot to add at least this:
    [pascal] // Turn off D3D lighting, since we are providing our own vertex colors
    g_d3d_device.SetRenderState(D3DRS_LIGHTING, iFalse);
    [/pascal]
    Actually very similar Direct3D starting tutorials from DirectX SDK (in Delphi, of cource) can be found here:simple Delphi Direct3D tutorials :roll:
    There are only 10 types of people in this world; those who understand binary and those who don't.

  3. #3

    Yay...

    Clootie: Thankyou..

    My problem was that lighting thing.. Strange, I havn't found that in OpenGl.
    It might be that I've been doing it and not noticeing..

    It works now, so all is well until the next problem.. ;}

    Armand

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •