using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace DirectX_004
{
public partial class BasicForm : Form
{
Device device = null;//定义绘图设备
public BasicForm()
{
this.ClientSize = new Size(800, 600);//指定窗口尺寸
this.Text = "DirectX程序!";//指定窗口标题
}
public bool InitializeDirect3D()
{
try
{
PresentParameters presentParams = new PresentParameters();
presentParams.Windowed = true;//指定以Windows窗体形式显示
presentParams.SwapEffect = SwapEffect.Discard;//当前屏幕绘制后它将自动从内存中删除
device = new Device(0, DeviceType.Hardware,
this, CreateFlags.SoftwareVertexProcessing, presentParams);//实例化device程序
return true;
}
catch (Direct3DXException e)
{
MessageBox.Show(e.ToString(), "Error");//处理异常
return false;
}
}
public void Render()
{
if (device == null)
{
return;
}
device.Clear(ClearFlags.Target, Color.DarkSlateGray, 1.0f, 0);
//清除Windows界面为深蓝色
device.BeginScene();
//在此添加渲染图形代码
device.EndScene();
device.Present();
}
}
static void Main()
{
BasicForm basicForm = new BasicForm();//创建窗体对象
if (basicForm.InitializeDirect3D() == false)//检查DirectX是否启动
{
MessageBox.Show("无法启动Direct3D", "错误!");
return;
}
basicForm.Show();//如果一切都初始化成功,则显示窗体
while (basicForm.Created)//设置一个循环用于实时更新渲染状态
{
basicForm.Render();//保持device渲染,直到程序结束
Application.DoEvents();//处理键盘鼠标等输入事件
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace DirectX_004
{
public partial class BasicForm : Form
{
Device device = null;//定义绘图设备
public BasicForm()
{
this.ClientSize = new Size(800, 600);//指定窗口尺寸
this.Text = "DirectX程序!";//指定窗口标题
}
public bool InitializeDirect3D()
{
try
{
PresentParameters presentParams = new PresentParameters();
presentParams.Windowed = true;//指定以Windows窗体形式显示
presentParams.SwapEffect = SwapEffect.Discard;//当前屏幕绘制后它将自动从内存中删除
device = new Device(0, DeviceType.Hardware,
this, CreateFlags.SoftwareVertexProcessing, presentParams);//实例化device程序
return true;
}
catch (Direct3DXException e)
{
MessageBox.Show(e.ToString(), "Error");//处理异常
return false;
}
}
public void Render()
{
if (device == null)
{
return;
}
device.Clear(ClearFlags.Target, Color.DarkSlateGray, 1.0f, 0);
//清除Windows界面为深蓝色
device.BeginScene();
//在此添加渲染图形代码
device.EndScene();
device.Present();
}
}
static void Main()
{
BasicForm basicForm = new BasicForm();//创建窗体对象
if (basicForm.InitializeDirect3D() == false)//检查DirectX是否启动
{
MessageBox.Show("无法启动Direct3D", "错误!");
return;
}
basicForm.Show();//如果一切都初始化成功,则显示窗体
while (basicForm.Created)//设置一个循环用于实时更新渲染状态
{
basicForm.Render();//保持device渲染,直到程序结束
Application.DoEvents();//处理键盘鼠标等输入事件
}
}
}