|
//-----------------------------------------------------------------------------
// File: CreateDevice.cs
// 创建设备
// Desc: This is the first tutorial for using Direct3D. In this tutorial, all
// we are doing is creating a Direct3D device and using it to clear the
// window.
// 注释:这是第一个使用D3D的教学例子,在这个例子中,我们要作的仅仅是创建以个D3D“设备”和刷新窗口
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
using System;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace DeviceTutorial
{
public class CreateDevice : Form
{
// Our global variables for this project
Device device = null; // Our rendering device
//我们的绘图设备
public CreateDevice()
{
// Set the initial size of our form
//设置窗体的初始值
this.ClientSize = new System.Drawing.Size(400,300);
// And it's caption
//设置窗体标题
this.Text = "D3D Tutorial 01: CreateDevice";
}
public bool InitializeGraphics()
{
try
{
// Now let's setup our D3D stuff
//现在我们设置D3D的一些选项
PresentParameters presentParams = new PresentParameters();
presentParams.Windowed=true;//标志着程序运行时窗口模式
presentParams.SwapEffect = SwapEffect.Discard;//返回或设置交换区选项????
device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams);
//?,设备的类型(这里选择了硬件),创建图形设备的窗体,创建类型,创建实体);
//创建设备实例
return true;
}
catch (DirectXException)//捕捉DX异常
{
return false;
}
}
private void Render()//刷新模块
{
if (device == null)
return;
//Clear the backbuffer to a blue color
//将设备窗口刷成绿色
device.Clear(ClearFlags.Target, System.Drawing.Color.Blue, 1.0f, 0);
//clear(刷屏的参数这里选的是目标,使用的颜色,深度(可能用于模板),模板(0)因为没有使用模板)
//Begin the scene
//开始渲染场景,(因为没有场景所以一下句是空的就直接结束了场景的渲染)
device.BeginScene();
// Rendering of scene objects can happen here
//可以在这里渲染场景
//End the scene
//结束场景的渲染
device.EndScene();
device.Present();
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) //重写 |