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}
另外, 因为有些日文的注释乱码, 也会让有些例子运行不了, 修改下乱码的地方即可.
目前我抽样测试了一些, 都没问题了.

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

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

本例效果图:

26153112_VGHZ.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

 
 
 
 
 

 

 

  

转载于:https://my.oschina.net/hermer/blog/319364

DirectX(Direct eXtension,简称DX),是由微软公司创建的多媒体编程接口。由C 编程语言实现,遵循COM。它能够帮助以windows为平台的游戏或多媒体程序获得更高的执行效率,加强3d图形和声音效果。   最新版本为DirectX 11,直接内置在windows7系统中,其他的系统则需要独立安装。   dx11 安装方法: 1、解压下载的文件。 2、双击“directx_11_redist.exe”,点击“YES”--“browse”--选择路径如c:\dx11。 3、进入c:\dx11目录,找到exe文件,双击安装,完成后重启。   DirectX 11 新技术: 1.Direct3D11渲染管线 DirectX 11加入了对Tessellation(镶嵌)的支持。Tessellation 由外壳着色器(Hull Shader)、镶嵌单元(tessellator)以及域着色器(Domain Shader)组成。同时还加入了计算着色器(Compute Shader) 2.Tessellation镶嵌技术 tessellator可以把一些较大的图元(primitive)分成很多更小的图元,并将这些小图元组合到一起,形成一种有序的几何图形,这种几何图形更复杂,当然也更接近现实。这个过程也被称作细分曲面(Subdivision Surfaces)。举例来说,tessellator可以让一个立方体,通过处理看起来像是个球形,这样的话无疑节省了空间。此外,图形的质量、性能以及可控性也达到了一定的促进。 3.多线程的支持 DX11特性还包括很重要一点:支持多线程(multi-threading)。DX11的这种多线程技术可能并不能加速绘图的子系统(特别是当我们的GPU资源受限时),但是这样却可以提升线程启动游戏的效率,并且可以利用台式CPU核心数量不断提高所带来的潜力。  4.计算着色器Compute Shader CS的这一渲染管线能够进行更多的通用目的运算。我们既能在某种可以用来被执行数据的操作中看到这种特性,又能在某种可以用来操作的数据中看到这种特性。  5.Shader Model 5.0 DirectX 11包含的SM 5.0,采用面向对象的概念,并且完全可以支持双精度数据。随着SM 5.0的发布,微软也会将HLSL语言更新至最新版本,其中包含了诸如动态着色、动态分支和更多的对象等。 6.改进的纹理压缩 DirectX 11提出了更为出色的纹理压缩算法——BC6和BC7。BC6是为HDR图像设计的压缩算法,压缩比为6∶1;而BC7是为低动态范围纹理设计的压缩模式,压缩比为3∶1。两种压缩算法在高压缩比下画质损失更少,效果更出色
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值