Building Direct3D Application from Delphi

Yesterday, I wrote how to build Direct3D application from Borland C++ Builder. But this time, i'll explained to you how to build using its "twin brothers" Borland Delphi. Well, the step by step it self is not so differ from the previous article. However, I was able to write this post since there were projects came over me last weeks regarding to the use of Direct3D on Borland Delphi 6 (BD6).

Firstly, you have to create a 3D object and export it to 3DS format file and then re-convert to X format file with tool conv3ds just like ussual (give a final file name with my_object.x). The texture design also have the same manner. You have to provide a picture with 256x256 pixel from image editor you likes and named it with my_pic.bmp.

The main differences came since i've use a component dedicatedly as an Direct3D retained mode (D3DRM) programming level. So, the code will absolutely more shorter because the primary initialization handled by the component. See this complete example below about how to show the 3D object on form:

uses dxtools, d3drm, d3drmobj, D3DTypes, D3DRMDef, DDraw, D3D, D3DCaps;
protected
procedure WMActivate(var Msg: TMessage); message WM_ACTIVATE;

//-----------------------------------------------------------//
//
template D3D //
//-----------------------------------------------------------//

procedure TForm.simulasiGO();
var cpos: D3DVECTOR;
begin
with D3DRM do
begin
if Initialized and not Failed then
begin
CenterScene;
DXCheck(Camera.GetPosition(Scene, cpos));
DXCheck(Camera.SetPosition(Scene, cam_x, cam_y , cam_z));
DXCheck(SubScene.GetPosition(Scene, cpos));
end;
end;
end;

procedure TForm.WMActivate(var Msg: TMessage);
begin
inherited;
D3DRM.ActivateCallback(Msg);
end;

procedure
TForm.D3DRMBuildScene(
Sender: TObject);
begin
D3DGM.LoadFile(my_object.x');
end;

procedure
TForm.Timer1Timer(Sender: TObject);
begin
timer_counter:=timer_counter+10;
with D3DRM do
begin
if (timer_counter<=(t*1000)) then DXCheck(SubScene.SetRotation(Scene,0,0,1,akselerasi)) else DXCheck(SubScene.SetRotation(Scene,0,0,0,0));

end;
end;

Pretty simple, isn't it? Okay, make a compile and here it is a snapshot of the application i've been made (a simulation of physic lessons material).

Sincerelly,

Eko Wahyudiharto
PS: If you've benefit from this blog,
you can support it by making a small contribution.

Enter your email address:

Delivered by FeedBurner

Post a Comment Bookmark and Share

 

  1. Blogger quang said,

    Friday, April 22, 2011 7:34:00 AM

    Oh, thank you very muck :)
    I want know more about it!!!
    let's send to email: tut4ever@ymail.com
    thanks =='

Post a Comment

Leave comments here...