C#DirectX双缓冲问题
在论坛里面找了找,发现这些问题全是GDI,Graphics,bitmap,想问各位高手,如果只是想单纯的在frontbuffer中自己绘制一条曲线,然后在backbuffer中绘制另一条曲线,曲线的绘制是DirectX渲染而成的,有可行性吗? --------------------编程问答-------------------- public bool InitializeGraphics(){
try
{
PresentParameters presentParams = new PresentParameters();
presentParams.Windowed = true;//在一个窗口显示//
presentParams.SwapEffect = SwapEffect.Discard;//设置后备缓存交换的方式//
presentParams.EnableAutoDepthStencil = true;//允许使用自动深度测试//
presentParams.AutoDepthStencilFormat = DepthFormat.D16;//尝试缓存区单元为16位2进制数//
device = new Device(0, DeviceType.Hardware, this.panel2, CreateFlags.SoftwareVertexProcessing, presentParams);//建立设备类对象//
device = new Device(0, DeviceType.Hardware, this.panel1, CreateFlags.SoftwareVertexProcessing, presentParams);
device.DeviceReset += new System.EventHandler(this.OnResetDevice);//设置设备重置事件(device.DeviceReset),事件函数为this.OnResetDevice//
this.OnCreateDevice(device, null);//自定义方法,初始化Device的工作放入其中//
this.OnResetDevice(device, null);//调用设备重置事件事件函数//
}
catch (DirectXException)
{ return false; }
return true;
}
//end//
public void OnCreateDevice(object sender, EventArgs e)
{
int List_Count = list.Count;
Device dev = (Device)sender;
vertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionColored), 1000, dev, 0, CustomVertex.PositionColored.Format, Pool.Default);
vertexBuffer.Created += new System.EventHandler(this.OnCreateVertexBuffer);
this.OnCreateVertexBuffer(vertexBuffer, null);//创建顶点数组并赋值//
}
//锁存坐标//
public void OnCreateVertexBuffer(object sender, EventArgs e)
{
StreamReader sr = new StreamReader("c:\\Book1.txt");
while (!sr.EndOfStream)
{
point3d point = new point3d();
string s = sr.ReadLine();
string[] array = s.Split(new char[] { ',' });
point.X = Convert.ToDouble(array[0]);
point.Y = Convert.ToDouble(array[1]);
point.Z = Convert.ToDouble(array[2]);
list.Add(point);
} int List_Count = list.Count;
point3d pt;
CustomVertex.PositionColored[] verts = (CustomVertex.PositionColored[])vertexBuffer.Lock(0, 0);
for (int i = 0; i <List_Count; i++)
{
pt = (point3d)list[i];
verts[i].Position = new Vector3((float)pt.X, (float)pt.Y, (float)pt.Z);
verts[i].Color = System.Drawing.Color.Black.ToArgb();
}
vertexBuffer.Unlock();
}
//增加世界观察投影变换//
private void SetupMatrices()
{
device.Transform.World = Matrix.RotationYawPitchRoll(yaw, pitch, roll);//世界变换,Y,X,Z轴旋转//
device.Transform.View = Matrix.LookAtLH(new Vector3(1.0f, 3.0f, ViewZ), new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 1.0f, 0.0f));//观察变换,参数1为观察者在世界空间位置,更改1可从不同角度观察图形,参数2为物体的世界空间中位置//
device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, 1.0f, 1.0f, 100.0f);
}
//重设Device参数//
public void OnResetDevice(object sender, EventArgs e)
{
Device dev = (Device)sender;
dev.RenderState.CullMode = Cull.None;
dev.RenderState.Lighting = false;
}
//渲染//
public void Render()
{
int List_Count = list.Count;
if (device == null)
return;
if (pause)
return;
device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.WhiteSmoke, 1.0f, 0);
SetupMatrices();
device.BeginScene();
device.SetStreamSource(0, vertexBuffer, 0);
device.VertexFormat = CustomVertex.PositionColored.Format;
device.DrawPrimitives(PrimitiveType.LineStrip, 0, List_Count-1);
device.DrawUserPrimitives(PrimitiveType.LineList, 3, verts1);
device.EndScene();
device.Present();
}
//当窗口在最小化或不是可视化的时候,停止渲染图形//
private void Form1_Resize(object sender, EventArgs e)
{ pause = ((this.WindowState == FormWindowState.Minimized) || !this.Visible); }
这是我的大致程序,请各位看看有没有实现的可能。怎么做才能显示两个交替的图像。
补充:.NET技术 , C#