Delphi 与 DirectX 之 DelphiX(1): 安装测试


测试 Demo 下载: http://files.cnblogs.com/del/DelphiX_1.rar (在 Delphi 2007 和 2009 下均编译通过)

其实按照 这里 的介绍, 比下载来的快, 也不需要下载.

DirectX, 微软很久的技术了; 从 Windows Vista 开始, DirectX 已经是微软操作系统的界面基础了.

在 Delphi 下使用 DirectX 比较流行的有下面四种方式:
DelphiX
DSPack
Asphyre (?)
Delphi DirectX

DelphiX 是最早的(十年了), 也是最简单的, 也是和 Delphi 结合最密切的;
但为了入手简单, 准备从 DelphiX 开始, 先有个宏观概念, 同时也学习一下 DelphiX 构造手法;
不过, 我想最终使用的应该是: Delphi DirectX.

DelphiX 从 2000.07.17 就没在更新过, 不过另有热心的支持者一直维护着, 甚至让它支持了 Delphi 2009.
我现在使用的版本是从这里下载的: http://www.micrel.cz/Dx/
使用了它的自动安装文件: http://www.micrel.cz/Dx/download/install.exe

尽管介绍是支持 Delphi 2009, 我还是发现了很多问题; 经过修正最后在 2009 下能用了.
但很多例子并不支持 2009, 因为在 2007 下要稳定得多, 所以选择在 Delphi 2007 下学习 DelphiX; 同时争取让代码兼容 2009.

为了保证运行所有的例子, 还需要把 DelphiXcfg.inc 的倒数第二行的 {.$Define D3DRM} 改为 {$Define D3DRM}
另外, 因为有些日文的注释乱码, 也会让有些例子运行不了, 修改下乱码的地方即可.
目前我抽样测试了一些, 都没问题了.

总感觉学晚了, 争取尽快超越它!

先从网上学了个例子, 作为开盘测试吧:

本例效果图:

o_09172.gif

代码文件:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DXDraws, StdCtrls, DXClass;

type
  TForm1 = class(TDXForm)
    DXDraw1: TDXDraw;
    DXTimer1: TDXTimer;
    DXImageList1: TDXImageList;
    procedure FormCreate(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure DXDraw1Initialize(Sender: TObject);
    procedure DXDraw1Finalize(Sender: TObject);
    procedure DXTimer1Timer(Sender: TObject; LagCount: Integer);
  private
    procedure CalculateTables;
    procedure PlotPoint(XCenter, YCenter, Radius, Angle: Word);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

var
  SineMove: array[0..255] of integer;
  CosineMove: array[0..255] of integer;
  SineTable: array[0..449] of integer;
  CenterX, CenterY: Integer;
  x: Word = 0;
  y: Word = 0;

procedure TForm1.CalculateTables;
var
  wCount: Word;
begin
  for wCount := 0 to 255 do
  begin
    SineMove[wCount] := round( sin( pi*wCount/128 ) * 45 );
    CosineMove[wCount] := round( cos( pi*wCount/128 ) * 60 );
  end; 
  for wCount := 0 to 449 do
  begin
    SineTable[wCount] := round( sin( pi*wCount/180 ) * 128);
  end;
end;

procedure TForm1.PlotPoint(XCenter, YCenter, Radius, Angle: Word);
var 
  a, b : Word;
begin
  a := ( Radius * SineTable[90 + Angle]);
  asm
    sar a,7
  end;
  a := CenterX + XCenter + a;
  b := ( Radius * SineTable[Angle] );
  asm
    sar b,7
  end;
  b := CenterY + YCenter + b;
  if (a < Width ) and ( b < Height ) then
  begin
    DXImageList1.Items[0].Draw(DXDraw1.Surface, a, b, 0 );
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  DXDraw1.Align := alClient;
  CenterX := Width div 2;
  CenterY := Height div 2;
  CalculateTables;
end;

procedure TForm1.DXDraw1Finalize(Sender: TObject);
begin
  DXTimer1.Enabled := False;
end;

procedure TForm1.DXDraw1Initialize(Sender: TObject);
begin
  DXTimer1.Enabled := True;
end;

procedure TForm1.DXTimer1Timer(Sender: TObject; LagCount: Integer);
const
  IncAngle = 12;
  XMove = 7;
  YMove = 8;
var
  CountAngle : Word;
  CountLong : Word;
  IncLong :Word;
begin
  if not DXDraw1.CanDraw then exit;
  IncLong := 2; 
  CountLong := 20; 
  DXDraw1.Surface.Fill(0);

  repeat
    CountAngle := 0;
    repeat
      PlotPoint(CosineMove[(x + (200 - CountLong)) mod 255],
                SineMove[(y + (200 - CountLong)) mod 255], CountLong, CountAngle);
      Inc(CountAngle, IncAngle);
    until CountAngle >= 360;

    inc(CountLong, IncLong);
    if (CountLong mod 3) = 0 then 
    begin
      inc(IncLong);
    end;
  until CountLong >= 270;

  x := XMove + x mod 255;
  y := YMove + y mod 255;

  with DXDraw1.Surface.Canvas do
  begin
    Brush.Style := bsClear; 
    Font.Color := clWhite;
    Font.Size := 12;
    Textout(0, 0, 'FPS: '+inttostr( DXTimer1.FrameRate)); { 录制动画是丢了这句 }
    Release;
  end;
  DXDraw1.Flip;
end;

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Key = VK_ESCAPE then Close;
end;

end.

窗体文件:
object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 206
  ClientWidth = 339
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  OnKeyDown = FormKeyDown
  PixelsPerInch = 96
  TextHeight = 13
  object DXDraw1: TDXDraw
    Left = 8
    Top = 8
    Width = 249
    Height = 177
    AutoInitialize = True
    AutoSize = True
    Color = clBlack
    Display.FixedBitCount = False
    Display.FixedRatio = True
    Display.FixedSize = True
    Options = [doAllowReboot, doWaitVBlank, doCenter, do3D, doDirectX7Mode, doHardware, doSelectDriver]
    SurfaceHeight = 177
    SurfaceWidth = 249
    OnFinalize = DXDraw1Finalize
    OnInitialize = DXDraw1Initialize
    TabOrder = 0
    Traces = <
      item
        Name = 'aaa'
        Active = True
        Tag = 0
        Blit.Active = True
        Blit.Z = 0
        Blit.Width = 0
        Blit.Height = 0
        Blit.Paths = {
          200000000080A8430000FE420000000019000000000000000000000000000000
          0000000000000000000000000000000000B0D7E2000080A74300000C43000000
          0019000000000000000000000000000000000000000000000000000000000000
          000030BD77050080A44300001843000000001900000000000000000000000000
          00000000000000000000000000000000000000F0BE770500809F430000234300
          0000001900000000000000000000000000000000000000000000000000000000
          00000000B0C077050080984300002D4300000000190000000000000000000000
          00000000000000000000000000000000000000000070C2770500809043000035
          4300000000190000000000000000000000000000000000000000000000000000
          00000000000030C477050000874300003B430000000019000000000000000000
          0000000000000000000000000000000000000000000000F0C577050000794300
          003F430000000019000000000000000000000000000000000000000000000000
          0000000000000000B0C777050000644300004043000000001900000000000000
          0000000000000000000000000000000000000000000000000070C9770500004F
          4300003F43000000001900000000000000000000000000000000000000000000
          0000000000000000000030CB770500003A4300003B4300000000190000000000
          000000000000000000000000000000000000000000000000000000C099400700
          0027430000354300000000190000000000000000000000000000000000000000
          000000000000000000000000809B40070000174300002D430000000019000000
          0000000000000000000000000000000000000000000000000000000000409D40
          0700000943000023430000000019000000000000000000000000000000000000
          0000000000000000000000000000009F40070000FE4200001843000000001900
          00000000000000000000000000000000000000000000000000000000000000C0
          A040070000F24200000C43000000001900000000000000000000000000000000
          0000000000000000000000000000000080A240070000EE420000FE4200000000
          1900000000000000000000000000000000000000000000000000000000000000
          0040A440070000F2420000E44200000000190000000000000000000000000000
          00000000000000000000000000000000000000A640070000FE420000CC420000
          0000190000000000000000000000000000000000000000000000000000000000
          000000C0A74007000009430000B6420000000019000000000000000000000000
          000000000000000000000000000000000000000080A94007000017430000A242
          0000000019000000000000000000000000000000000000000000000000000000
          000000000040AB40070000274300009242000000001900000000000000000000
          0000000000000000000000000000000000000000000000AD400700003A430000
          8642000000001900000000000000000000000000000000000000000000000000
          00000000000000C0AE400700004F4300007C4200000000190000000000000000
          00000000000000000000000000000000000000000000000080B0400700006443
          0000784200000000190000000000000000000000000000000000000000000000
          00000000000000000040B240070000794300007C420000000019000000000000
          000000000000000000000000000000000000000000000000000000B440070000
          8743000086420000000019000000000000000000000000000000000000000000
          0000000000000000000000C0B540070080904300009242000000001900000000
          0000000000000000000000000000000000000000000000000000000080B74007
          008098430000A242000000001900000000000000000000000000000000000000
          0000000000000000000000000040B9400700809F430000B64200000000190000
          00000000000000000000000000000000000000000000000000000000000000BB
          40070080A4430000CC4200000000190000000000000000000000000000000000
          000000000000000000000000000000C0BC40070080A7430000E4420000000019
          0000000000000000000000000000000000000000000000000000000000000000
          80BE4007}
      end>
  end
  object DXTimer1: TDXTimer
    ActiveOnly = True
    Enabled = False
    Interval = 10
    OnTimer = DXTimer1Timer
    Left = 160
    Top = 104
  end
  object DXImageList1: TDXImageList
    DXDraw = DXDraw1
    Items.ColorTable = {
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000}
    Items = <
      item
        PatternHeight = 0
        PatternWidth = 0
        Picture.Data = {
          0454444942280000000200000001000000010008000000000004000000000000
          0000000000000000000000000099FFFF00FFFFFF000000000000000000000000
          0000000000000000000000000000000000000000000000000000000000000000
          0000000000000000000000000000000000000000000000000000000000000000
          0000000000000000000000000000000000000000000000000000000000000000
          0000000000000000000000000000000000000000000000000000000000000000
          0000000000000000000000000000000000000000000000000000000000000000
          0000000000000000000000000000000000000000000000000000000000000000
          0000000000000000000000000000000000000000000000000000000000000000
          0000000000000000000000000000000000000000000000000000000000000000
          0000000000000000000000000000000000000000000000000000000000000000
          0000000000000000000000000000000000000000000000000000000000000000
          0000000000000000000000000000000000000000000000000000000000000000
          0000000000000000000000000000000000000000000000000000000000000000
          0000000000000000000000000000000000000000000000000000000000000000
          0000000000000000000000000000000000000000000000000000000000000000
          0000000000000000000000000000000000000000000000000000000000000000
          0000000000000000000000000000000000000000000000000000000000000000
          0000000000000000000000000000000000000000000000000000000000000000
          0000000000000000000000000000000000000000000000000000000000000000
          0000000000000000000000000000000000000000000000000000000000000000
          0000000000000000000000000000000000000000000000000000000000000000
          0000000000000000000000000000000000000000000000000000000000000000
          0000000000000000000000000000000000000000000000000000000000000000
          0000000000000000000000000000000000000000000000000000000000000000
          0000000000000000000000000000000000000000000000000000000000000000
          0000000000000000000000000000000000000000000000000000000000000000
          0000000000000000000000000000000000000000000000000000000000000000
          0000000000000000000000000000000000000000000000000000000000000000
          0000000000000000000000000000000000000000000000000000000000000000
          0000000000000000000000000000000000000000000000000000000000000000
          0000000000000000000000000000000000000000000000000000000000000000
          0000000000000000000000000000000000000000000000000000000000000000
          0000000000000000000000000001000000}
        SystemMemory = False
        Transparent = True
        TransparentColor = clWhite
      end>
    Left = 192
    Top = 96
  end
end
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
DirectX 简介  DirectX 对于大多数游戏爱好者来说都不陌生(当然,那些只在DOS下艰苦作战的朋友例外),在安装一个游戏前,系统总是会提示你是否需要同时升级 DirectX。简单地说,DirectX 就是一系列的 DLL (动态连接库),通过这些 DLL,开发者可以在无视于设备差异的情况下访问底层的硬件。DirectX 封装了一些 COM(Component Object Model)对象,这些 COM 对象为访问系统硬件提供了一个主要的接口。DirectX 目前主要由以下七个主要部分组成:DirectDraw – 为程序直接访问显存提供接口,同时和其它的Windows应用程序保持兼容。 Direct3D – 为访问3D加速设备提供接口。 DirectInput – 为各种输入设备提供接口,比如鼠标,键盘,力反馈游戏手柄和操纵杆等。 DirectPlay – 为游戏提供网络功能接口,比如支持通过 TCP/I、IPX 等协议进行游戏中的数据传输。 DirectSound – 为访问声卡提供接口,支持WAV、MIDI 等文件的直接播放。 DirectSound3D –通过此接口,可以模拟出某一个声音在三维空间中任何一个位置的播放所产生的效果,从而达到逼真的环绕立体声。 DirectMusic – 此接口主要是生成一系列的原始声音采样反馈给相应的用户事件。 组件列表:TDXDraw DirectDraw 和 Direct3D 组件 TDXDIB 容纳DIB(设备无关位图,Device Independent Bitmap)的组件 TDXImageList 图片列表组件 TDX3D Direct3D 组件 (和TDXDraw一起使用) TDXSound DirectSound 组件 TDXWave 容纳 Wave(波形音频文件)的组件 TDXWaveList Wave文件列表组件 TDXInput 输入组件,包括键盘和手柄输入 TDXPlay 通讯组件,用于网络游戏开发 TDXSpriteEngine 精灵引擎,用于管理游戏中产生的精灵(Sprite)详见游戏开发过程 TDXTimer 高速定时器,比 TTimer 要更快,更准确 TDXPaintBox TpaintBox 的 DIB 版本 TDXForm 优化过的 TForm,专门用于游戏开发 目前的 DelphiX 包支持 Borland Delphi 3/4/5/6 和 DirectX 7.0 以上版本,D7下测试也可。安装DelphiX 之后,我们将不需要再安装微软的 DirectX SDK。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值