zoukankan      html  css  js  c++  java
  • DX之“HelloWord”

    目标:使用VS建立窗口程序,通过DX绘制窗口背景色。

    1,安装DX(含有托管的版本)。

    2,使用VS建立窗口程序。

    3,引入托管DX环境。

    image

    4,编写基础代码。全部在MainForm代码文件中。

    原始代码:

    image

    修改后代码

    引入DX

    image

    public partial class MainForm : Form
    {
       public MainForm()
       {
           InitializeComponent();
           this.InitialDX();
       }
     
       private Device device = null;
     
       private void InitialDX()
       {
           PresentParameters presentParams = new PresentParameters();
           presentParams.Windowed = true;
           presentParams.SwapEffect = SwapEffect.Discard;
     
           device = new Device(
               0,
               DeviceType.Hardware,
               this,
               CreateFlags.SoftwareVertexProcessing,
               presentParams);
       }
     
       protected override void OnPaint(PaintEventArgs e)
       {
           base.OnPaint(e);
           this.DrawDX();
       }
     
       private void DrawDX()
       {
           if (this.device == null)
               return;
     
           this.device.Clear(ClearFlags.Target,
               Color.AliceBlue,
               1f,
               0);
     
           this.device.BeginScene();
           //绘制DX图形
           this.device.EndScene();
     
           this.device.Present();//显示图形
       }
    }

    效果:

    image

    注:

    1,所有的绘制在 BeginScene和EndScene之间完成。

    2,窗体背景颜色设置主要使用了Device.Clear 方法

    public void Clear(
    	ClearFlags flags,
    	Color color,
    	float zdepth,
    	int stencil
    )
    将视区或视区中的一组矩形清除为指定的 RGBA 颜色,清除深度缓冲区并清除模具缓冲区。
    参数:
    flags
    类型:Microsoft.WindowsMobile.DirectX.Direct3D.ClearFlags

    指示要清除的图面的标志。此参数可以是下列标志的任意组合,但必须至少使用一个标志:

    • Stencil:将模具缓冲区清除为 stencil 参数中的值。

    • Target:将呈现目标清除为 color 参数中的颜色。

    • ZBuffer:将深度缓冲区清除为 zdepth 参数中的值。

    color
    类型:System.Drawing.Color

    一个 Color 对象,它表示将呈现目标图面清除为的颜色。

    zdepth
    类型:System.Single

    此方法存储在深度缓冲区中的新 zdepth 值。此参数的范围可以在 0.0 到 1.0 之间(对于基于 z 或基于 w 的深度缓冲区)。如果值为 0.0,表示与查看器的最近距离;如果值为 1.0,则表示最远距离。

    stencil
    类型:System.Int32

    要存储在每个模具缓冲区项中的整数值。此参数的范围可以在 0 到 2n-1 之间,其中 n 是模具缓冲区的位深度。

  • 相关阅读:
    爬虫流程
    康哥笔记
    csdn笔记
    数据库多表联查
    完整数据恢复
    Linux安装mysql
    linux在vm下实现桥接模式
    Linux下ntpdate时间同步
    spark集群在执行任务出现nitial job has not accepted any resources; check your cluster UI to ensure that worker
    flume在启动时出现brokerList must contain at least one Kafka broker
  • 原文地址:https://www.cnblogs.com/sharpfeng/p/1950626.html
Copyright © 2011-2022 走看看