从今天开始,要好好学习direct了,先从简单的学起,用c#+direct 9入门。
今天迈出第一步,初始化
Device device = null
PresentParameters presentParams = new PresentParameters();
presentParams.Windowed=true;
presentParams.SwapEffect = SwapEffect.Discard;
device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams);
这是sdk自带的一部分代码,其中device就是显示设备,device的构造函数有多个重载,如下
在第二个和第三个构造函数中,第三个参数都是device指定显示的地方。显示的地方可以是控件也可以是form
我想,做个3D的控件然后再放入程序,也应该是很酷的,哈哈
PresenParameters[]就是显示的参数,主要设置显示的缓冲以及其他,可以参照帮助文档(可以不设置值,都有默认参数)
这样一个显示的设备就生成好了
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);
//Begin the scene
device.BeginScene();
// Rendering of scene objects can happen here
//End the scene
device.EndScene();
device.Present();
}
这个就是一个图形显示函数了,其实什么也没有干,就是把背景用蓝色给刷了一遍。
device.BeginScene()
就是开始画图,和opengl里的begin函数一样,endScene也是一样
Presents the display with the contents of the next buffer in the sequence of back buffers owned by the device
device.Present()就是将刚才存储到beginScene和EndScene里的函数画出来,和OG里Flush功能类似
今天迈出第一步,初始化
Device device = null
PresentParameters presentParams = new PresentParameters();
presentParams.Windowed=true;
presentParams.SwapEffect = SwapEffect.Discard;
device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams);
这是sdk自带的一部分代码,其中device就是显示设备,device的构造函数有多个重载,如下
public Device(IDirect3DDevice9); |
public Device(int, DeviceType, Control, CreateFlags, PresentParameters[]); |
public Device(int, DeviceType, IntPtr, CreateFlags, PresentParameters[]); |
public Device(IntPtr); |
我想,做个3D的控件然后再放入程序,也应该是很酷的,哈哈
PresenParameters[]就是显示的参数,主要设置显示的缓冲以及其他,可以参照帮助文档(可以不设置值,都有默认参数)
这样一个显示的设备就生成好了
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);
//Begin the scene
device.BeginScene();
// Rendering of scene objects can happen here
//End the scene
device.EndScene();
device.Present();
}
这个就是一个图形显示函数了,其实什么也没有干,就是把背景用蓝色给刷了一遍。
device.BeginScene()
就是开始画图,和opengl里的begin函数一样,endScene也是一样
Presents the display with the contents of the next buffer in the sequence of back buffers owned by the device
device.Present()就是将刚才存储到beginScene和EndScene里的函数画出来,和OG里Flush功能类似