Today's my MDX...
生活随笔
收集整理的這篇文章主要介紹了
Today's my MDX...
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Have been read "Rendering Using Simple Techniques" from "Managed DirectX? 9 Kick Start: Graphics and Game Programming" which writed by Tom?Miller?(His blog is http://blogs.msdn.com/tmiller/)...
問題
# 為什么全屏下的MDX程序,包括系統里面那個Dxdiag的DX檢測程序,當點擊程序或者屏幕左上角和右上角的時候,程序會退出?(包括一個利用MDX開發的游戲也出現這種情況).
# 怎樣設置一下VS2003,使其對MDX的出錯信息進行調試?
程序-創建一個Texture化的3D三角形
//(1)在Form1的構造函數里面設置
this.SetStyle(ControlStyles.AllPaintingInWmPaint?|?ControlStyles.Opaque,true);
this.Load+=new?EventHandler(InitGraph);
//(2)按下TAB鍵可以創建InitGraph(object?sender,EventArgs?e)
????????private?void?InitGraph(object?sender,?EventArgs?e)
????????{}{
????????????PresentParameters?pp=new?PresentParameters();
????????????pp.SwapEffect=SwapEffect.Discard;
????????????pp.Windowed=true;
????????????device?=?new?Device(0,DeviceType.Hardware,this,CreateFlags.HardwareVertexProcessing,pp);
????????????vb?=?new?VertexBuffer(typeof(CustomVertex.PositionTextured),36,device,Usage.Dynamic?|?
Usage.WriteOnly,
????????????????CustomVertex.PositionTextured.Format,Pool.Default);
????????????vb.Created+=new?EventHandler(vb_Created);
vb_Created(vb,null);
????????}
//(3)按下TAB鍵可以創建vb_Created了
????????private?void?vb_Created(object?sender,?EventArgs?e)
????????{}{
????????????VertexBuffer?buf=(VertexBuffer)sender;
????????????//創建三角形,注意是PositionTextured
????????????CustomVertex.PositionTextured[]?verts=new?Microsoft.DirectX.Direct3D.CustomVertex.PositionTextured
[3];
????????????verts[0]=new?Microsoft.DirectX.Direct3D.CustomVertex.PositionTextured(0,4,0,0.0f,0.0f);
????????????verts[1]=new?Microsoft.DirectX.Direct3D.CustomVertex.PositionTextured(-3,0,0,0.0f,1.0f);
????????????verts[2]=new?Microsoft.DirectX.Direct3D.CustomVertex.PositionTextured(3,0,0,1.0f,0.0f);
????????????buf.SetData(verts,0,LockFlags.None);
????????????//??LockFlags
????????}
//(4)重寫OnPaint
????????protected?override?void?OnPaint(PaintEventArgs?e)
????????{}{
????????????device.Clear(ClearFlags.Target,System.Drawing.Color.Aqua,1.0f,0);
????????????this.SetCamera();
????????????this.DrawSence();
????????????this.Invalidate();
????????}
//(5)完成OnPaint里面幾個函數
????????private?void?SetCamera()
????????{}{
????????????device.Transform.World?=?Matrix.RotationAxis(new?Vector3(angle/((float)Math.PI*2.0f),angle/((float)
Math.PI*4.0f),
????????????????angle/((float)Math.PI*6.0f)),angle/(float)Math.PI);
????????????angle?+=?0.1f;
????????????device.Transform.Projection?=?Matrix.PerspectiveFovLH((float)Math.PI/4,?this.Width/this.Height,?1.0f,?
100.0f);
????????????device.Transform.View?=?Matrix.LookAtLH(new?Vector3(0,0,5.0f),new?Vector3(),new?Vector3(0,1,0));
????????????device.RenderState.Lighting?=?false;
????????}
????????private?void?DrawSence()
????????{}{
????????????device.BeginScene();
????????????device.VertexFormat=CustomVertex.PositionTextured.Format;
????????????device.SetStreamSource(0,vb,0);
????????????device.DrawPrimitives(PrimitiveType.TriangleList,0,1);
????????????device.EndScene();
????????????device.Present();
????????}
//(6)添加Texture
//在InitGraph()的最后
tex=new?Texture(device,new?Bitmap("T.bmp"),0,Pool.Managed);
//在DrawSence()里面的device.SetStreamSource()后
device.SetTexture(0,tex);
轉載于:https://www.cnblogs.com/caca/archive/2005/08/06/208700.html
總結
以上是生活随笔為你收集整理的Today's my MDX...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 英特尔 Arc & Iris 显
- 下一篇: 三年之期已到 不换APP享受自由音乐的理