本文整理汇总了C#中Device.Present方法的典型用法代码示例。如果您正苦于以下问题:C# Device.Present方法的具体用法?C# Device.Present怎么用?C# Device.Present使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Device
的用法示例。
在下文中一共展示了Device.Present方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
var form = new Form1();
var panel = form.SplitContainer.Panel1;
var device = new Device(new Direct3D(), 0, DeviceType.Hardware, panel.Handle, CreateFlags.HardwareVertexProcessing, new PresentParameters()
{
BackBufferWidth = panel.ClientSize.Width,
BackBufferHeight = panel.ClientSize.Height
});
var vertices = new VertexBuffer(device, 3 * 20, Usage.WriteOnly, VertexFormat.None, Pool.Managed);
vertices.Lock(0, 0, LockFlags.None).WriteRange(new[] {
new Vertex() { Color = Color.Red.ToArgb(), Position = new Vector4(400.0f, 100.0f, 0.5f, 1.0f) },
new Vertex() { Color = Color.Blue.ToArgb(), Position = new Vector4(650.0f, 500.0f, 0.5f, 1.0f) },
new Vertex() { Color = Color.Green.ToArgb(), Position = new Vector4(150.0f, 500.0f, 0.5f, 1.0f) }
});
vertices.Unlock();
var vertices2 = new VertexBuffer(device, 3 * 20, Usage.WriteOnly, VertexFormat.None, Pool.Managed);
vertices2.Lock(0, 0, LockFlags.None).WriteRange(new[] {
new Vertex() { Color = Color.Red.ToArgb(), Position = new Vector4(300.0f, 100.0f, 0.5f, 1.0f) },
new Vertex() { Color = Color.Blue.ToArgb(), Position = new Vector4(550.0f, 500.0f, 0.5f, 1.0f) },
new Vertex() { Color = Color.Green.ToArgb(), Position = new Vector4(050.0f, 500.0f, 0.5f, 1.0f) }
});
vertices2.Unlock();
var vertexElems = new[] {
new VertexElement(0, 0, DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.PositionTransformed, 0),
new VertexElement(0, 16, DeclarationType.Color, DeclarationMethod.Default, DeclarationUsage.Color, 0),
VertexElement.VertexDeclarationEnd
};
var vertexDecl = new VertexDeclaration(device, vertexElems);
MessagePump.Run(form, () =>
{
device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
device.BeginScene();
device.SetStreamSource(0, vertices, 0, 20);
device.VertexDeclaration = vertexDecl;
device.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);
device.SetStreamSource(0, vertices2, 0, 20);
device.VertexDeclaration = vertexDecl;
device.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);
device.EndScene();
device.Present();
});
foreach (var item in ObjectTable.Objects)
item.Dispose();
}
示例2: loop
public override void loop(Device i_d3d)
{
lock (this._ss)
{
this._ms.update(this._ss);
this._rs.drawBackground(i_d3d, this._ss.getSourceImage());
i_d3d.BeginScene();
i_d3d.Clear(ClearFlags.ZBuffer, Color.DarkBlue, 1.0f, 0);
if (this._ms.isExistMarker(this.mid))
{
//get marker plane pos from Mouse X,Y
Point p=this.form.PointToClient(Cursor.Position);
Vector3 mp = new Vector3();
this._ms.getMarkerPlanePos(this.mid, p.X,p.Y,ref mp);
mp.Z = 20.0f;
//立方体の平面状の位置を計算
Matrix transform_mat2 = Matrix.Translation(mp);
//変換行列を掛ける
transform_mat2 *= this._ms.getD3dMarkerMatrix(this.mid);
// 計算したマトリックスで座標変換
i_d3d.SetTransform(TransformType.World, transform_mat2);
// レンダリング(描画)
this._rs.colorCube(i_d3d, 40);
}
i_d3d.EndScene();
}
i_d3d.Present();
}
示例3: Run
public void Run()
{
Output.Clear();
var window = new Window();
var device = new Device(window);
device.Run();
Output.Add("RunnerTests.Run");
device.Present();
const string ExpectedOutput = "Window.Run, Device.Run, RunnerTests.Run, Device.Present";
Assert.AreEqual(ExpectedOutput, Output.ToText());
}
示例4: TextureViewer_Load
void TextureViewer_Load(object sender, EventArgs e)
{
this.Show();
Application.DoEvents();
pp = new PresentParameters();
pp.BackBufferCount = 2;
pp.SwapEffect = SwapEffect.Discard;
pp.Windowed = true;
Direct3D d3d = new Direct3D();
d3d_device = new Device(d3d, 0, DeviceType.Hardware, d3dPanel.Handle, CreateFlags.HardwareVertexProcessing, pp);
texture = Texture.FromFile(d3d_device, texturePath);
int texWidth = texture.GetLevelDescription(0).Width;
int texHeight = texture.GetLevelDescription(0).Height;
d3dPanel.Top = menuStrip1.Height;
d3dPanel.Left = 0;
d3dPanel.ClientSize = new Size(texWidth, texHeight);
this.ClientSize = new System.Drawing.Size(
d3dPanel.Width,
d3dPanel.Height + menuStrip1.Height
);
pp.BackBufferWidth = texWidth;
pp.BackBufferHeight = texHeight;
d3d_device.Reset(pp);
sprite = new Sprite(d3d_device);
while (this.Visible)
{
d3d_device.Clear(ClearFlags.ZBuffer | ClearFlags.Target, new Color4(Color.Black), 1.0f, 0);
d3d_device.BeginScene();
sprite.Begin(SpriteFlags.AlphaBlend);
Rectangle rect = new Rectangle()
{
X = 0,
Y = 0,
Width = texture.GetLevelDescription(0).Width,
Height = texture.GetLevelDescription(0).Height
};
sprite.Draw(texture, rect, new Color4(Color.White));
sprite.End();
d3d_device.EndScene();
d3d_device.Present();
Application.DoEvents();
}
}
示例5: DrawBox
/*
private void DrawBox(float yaw, float pitch, float roll, float x, float y, float z)
{
angle += 0.01f;
device.Transform.World = Matrix.RotationYawPitchRoll(yaw, pitch, roll) * Matrix.Translation(x, y, z);
device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, verts.Length, 0, indices.Length / 3);
}
*/
/// <summary>
/// render 3D objects
/// </summary>
/// <param name="d3d"></param>
/// <param name="dx"></param>
private void render3D(Device dx)
{
if ((initialised_3D) && (selected_display == MonoSLAM.DISPLAY_AUGMENTED_REALITY))
{
if ((test.enable_mapping) && (!test.calibrating))
{
// Set the position of the camera
Vector3D camera_position = null;
SceneLibrary.Quaternion camera_orientation = null;
test.getCameraPositionOrientation(ref camera_position, ref camera_orientation);
dx.Transform.View = QuaternionToMatrixLookAt(camera_position, camera_orientation);
/*
Microsoft.DirectX.Quaternion q_orientation =
new Microsoft.DirectX.Quaternion((float)camera_orientation.GetX(),
(float)camera_orientation.GetY(),
(float)camera_orientation.GetZ(),
(float)camera_orientation.GetR());
Matrix _matrixRotation = Matrix.RotationQuaternion(q_orientation);
float yaw = 0, pitch = 0, roll = 0;
camera_orientation.GetZYXEuler(ref pitch, ref yaw, ref roll);
dx.Transform.View = QuaternionToMatrixLookAt(camera_position, camera_orientation) *
Matrix.RotationYawPitchRoll(0,0,(float)(roll));
*/
//dx.Material = InitMaterial(Color.White);
dx.Clear(ClearFlags.ZBuffer, Color.FromArgb(255, 0, 0, 0), 1.0f, 0);
//dx.Clear(ClearFlags.Target | ClearFlags.ZBuffer,Color.FromArgb(255, 0, 0, 0), 1.0f, 0);
//dx.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Transparent, 1.0f, 0);
if (background_image == null)
background_image = new D3D_background(dx, background_bitmap);
else
background_image.update(dx, background_bitmap);
background_image.Draw();
/*
dx.BeginScene();
dx.Transform.World = Matrix.Identity;
ScaleMatrices(dx, 1000, 0.1f, 0.1f);
dx.VertexFormat = Vertex.FVF_Flags;
dx.SetStreamSource(0, lineVertexBuffer, 0);
//dx.SetTexture(0, texture);
dx.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
dx.DrawPrimitives(PrimitiveType.TriangleStrip, 4, 2);
dx.EndScene();
// this try/catch prevents an error if the scene is being rendered
// whilst the window is being closed
try
{
dx.Present();
}
catch
{
}
dx.BeginScene();
dx.Transform.World = Matrix.Identity;
ScaleMatrices(dx, 0.1f, 1000, 0.1f);
dx.VertexFormat = Vertex.FVF_Flags;
dx.SetStreamSource(0, lineVertexBuffer, 0);
//dx.SetTexture(0, texture);
dx.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
dx.DrawPrimitives(PrimitiveType.TriangleStrip, 4, 2);
dx.EndScene();
// this try/catch prevents an error if the scene is being rendered
//.........这里部分代码省略.........
示例6: Main
static void Main()
{
MainForm parent = new MainForm();
RenderForm form = new RenderForm("SlimDX - MiniTri Direct3D9 Sample");
form.Location = new Point(8, 24);
form.TopLevel = false;
parent.Controls.Add(form);
parent.Size = new Size(900, 600);
form.ClientSize = new Size((GameTypes.MAP_WIDTH*GameTypes.SPRITE_WIDTH), (GameTypes.MAP_HEIGHT*GameTypes.SPRITE_HEIGHT));
parent.Controls.Add(new Button());
parent.Show();
//Icon ico = new Icon("assets//textures//icon.bmp");
form.Click += new EventHandler(form_Click);
form.MouseMove += new MouseEventHandler(form_MouseMove);
form.MouseLeave += new EventHandler(form_MouseLeave);
form.MouseEnter += new EventHandler(form_MouseEnter);
form.KeyDown += new KeyEventHandler(form_KeyDown);
form.KeyUp += new KeyEventHandler(form_KeyUp);
form.LostFocus += new EventHandler(form_LostFocus);
form.Focus();
parent.KeyDown += new KeyEventHandler(form_KeyDown);
parent.KeyUp += new KeyEventHandler(form_KeyUp);
form.FormBorderStyle = FormBorderStyle.None;
Device device = new Device(new Direct3D(), 0, DeviceType.Hardware, form.Handle, CreateFlags.HardwareVertexProcessing, new PresentParameters()
{
BackBufferWidth = form.ClientSize.Width,
BackBufferHeight = form.ClientSize.Height
});
Maze testmaze = new Maze();
testmaze.Initialize();
testmaze.Generate();
int[,] walkable = new int[GameTypes.MAP_WIDTH, GameTypes.MAP_WIDTH];
walkable = testmaze.getWalkableArray();
TextureManager.Instance.init(device);
GameEngine.Instance.init();
WindowManager.Instance.Main = parent;
WindowManager.Instance.Slim = form;
GameEngine.Instance.LifeTimer.Start();
GameEngine.Instance.FPSTimer.Start();
GameEngine.Instance.TestSpriteTimer.Start();
PathFinding.Instance.init(GameTypes.MAP_WIDTH,GameTypes.MAP_HEIGHT);
GameEngine.Instance.testvec = new Vector3(5 * 32, 5 * 632, 0);
Enemy e = new Enemy(GameTypes.ENEMY_UNI);
e.StackTest();
GameEngine.Instance.testEnemy = new Enemy(GameTypes.ENEMY_UNI);
GameEngine.Instance.Enemies = new System.Collections.Generic.List<Enemy>();
GameEngine.Instance.LifeTimer.Stop();
//for (int i = 0; i < 10; i++)
//{
// Enemy enemy = new Enemy(GameTypes.ENEMY_UNI);
// enemy.BirthTime = (float)GameEngine.Instance.LifeTimer.Elapsed + i;
// GameEngine.Instance.Enemies.Add(enemy);
//}
//close some nodes
//PathFinding.Instance.Nodes[4 + 10].Walkable = false;
//PathFinding.Instance.Nodes[4 + 20].Walkable = false;
//PathFinding.Instance.Nodes[4 + 30].Walkable = false;
//PathFinding.Instance.Nodes[4 + 40].Walkable = false;
//PathFinding.Instance.Nodes[4 + 50].Walkable = false;
//PathFinding.Instance.Nodes[4 + 60].Walkable = false;
//PathFinding.Instance.Nodes[4 + 70].Walkable = false;
//PathFinding.Instance.Nodes[4 + 80].Walkable = false;
for (int y = 0; y < GameTypes.MAP_HEIGHT; y++)
{
for (int x = 0; x < GameTypes.MAP_WIDTH; x++)
{
if (walkable[x, y] == 0 || y == GameTypes.MAP_HEIGHT - 1)
{
PathFinding.Instance.GetNode(x, y).Walkable = false;
}
}
}
PathFinding.Instance.GetNode(GameTypes.PLAYER_START_COORDS).Walkable = true;
GameEngine.Instance.SpawnEnemy(GameEngine.Instance.PlayerLevel);
GameEngine.Instance.PlaceShiny();
WindowManager.Instance.Main.lblScore.Text = "SCORE: " + GameEngine.Instance.PlayerScore.ToString();
WindowManager.Instance.Main.lblLife.Text = "LIFE";
WindowManager.Instance.Main.ShowLife();
WindowManager.Instance.Main.lblHiscore.Text = "HI-SCORE " + GameEngine.Instance.HiScore.ToString();
MessagePump.Run(form, () =>
{
//.........这里部分代码省略.........
示例7: MainWindow_OnLoaded
private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
{
var bmp = new WriteableBitmap(640, 480, 32, 32, PixelFormats.Bgra32, null);
_device = new Device(bmp);
_image.Source = bmp;
var mesh = new Mesh("Cube", 8, 12);
meshes.Add(mesh);
mesh.Vertices[0] = new Vector3(-1, 1, 1);
mesh.Vertices[1] = new Vector3(1, 1, 1);
mesh.Vertices[2] = new Vector3(-1, -1, 1);
mesh.Vertices[3] = new Vector3(1, -1, 1);
mesh.Vertices[4] = new Vector3(-1, 1, -1);
mesh.Vertices[5] = new Vector3(1, 1, -1);
mesh.Vertices[6] = new Vector3(1, -1, -1);
mesh.Vertices[7] = new Vector3(-1, -1, -1);
mesh.Faces[0] = new Face { A = 0, B = 1, C = 2 };
mesh.Faces[1] = new Face { A = 1, B = 2, C = 3 };
mesh.Faces[2] = new Face { A = 1, B = 3, C = 6 };
mesh.Faces[3] = new Face { A = 1, B = 5, C = 6 };
mesh.Faces[4] = new Face { A = 0, B = 1, C = 4 };
mesh.Faces[5] = new Face { A = 1, B = 4, C = 5 };
mesh.Faces[6] = new Face { A = 2, B = 3, C = 7 };
mesh.Faces[7] = new Face { A = 3, B = 6, C = 7 };
mesh.Faces[8] = new Face { A = 0, B = 2, C = 7 };
mesh.Faces[9] = new Face { A = 0, B = 4, C = 7 };
mesh.Faces[10] = new Face { A = 4, B = 5, C = 6 };
mesh.Faces[11] = new Face { A = 4, B = 6, C = 7 };
camera.Position = new Vector3(0, 0, 10.0f);
camera.Target = Vector3.Zero;
CompositionTarget.Rendering += (o, args) => {
_device.Clear(0, 0, 0, 255);
mesh.Rotation = new Vector3(mesh.Rotation.X + 0.01f, mesh.Rotation.Y + 0.01f, mesh.Rotation.Z);
_device.Render(camera, mesh);
_device.Present();
};
}
示例8: Start
public override void Start()
{
base.Start();
var form = new RenderForm("02_vertex_and_fragment_program");
this.device = new Device(new Direct3D(), 0, DeviceType.Hardware, form.Handle, CreateFlags.HardwareVertexProcessing, new PresentParameters
{
BackBufferWidth = form.ClientSize.Width,
BackBufferHeight = form.ClientSize.Height
});
int vertexCount = 0;
for (int i = 0; i < MyStarCount; i++)
{
vertexCount += myStarList[i].Points * 2 + 2;
}
vertexBuffer = new VertexBuffer(device, vertexCount * 12, Usage.WriteOnly, VertexFormat.Position, Pool.Default);
Vector3[] starVertices = new Vector3[vertexCount];
var dataStream = vertexBuffer.Lock(0, 0, LockFlags.Discard);
for (int i = 0, n = 0; i < myStarList.Length; i++)
{
double piOverStarPoints = 3.14159 / myStarList[i].Points;
float x = myStarList[i].X,
y = myStarList[i].Y,
outerRadius = myStarList[i].OuterRadius,
r = myStarList[i].InnerRadius;
double angle = 0.0;
/* Center of star */
starVertices[n++] = new Vector3(x, y, 0);
/* Emit exterior vertices for star's points. */
for (int j = 0; j < myStarList[i].Points; j++)
{
starVertices[n++] = new Vector3(x + outerRadius * (float)Math.Cos(angle), y + outerRadius * (float)Math.Sin(angle), 0);
angle -= piOverStarPoints;
starVertices[n++] = new Vector3(x + r * (float)Math.Cos(angle), y + r * (float)Math.Sin(angle), 0);
angle -= piOverStarPoints;
}
/* End by repeating first exterior vertex of star. */
angle = 0;
starVertices[n++] = new Vector3(x + outerRadius * (float)Math.Cos(angle), y + outerRadius * (float)Math.Sin(angle), 0);
}
dataStream.WriteRange(starVertices);
dataStream.Position = 0;
vertexBuffer.Unlock();
this.CgContext = Context.Create();
this.CgContext.ParameterSettingMode = ParameterSettingMode.Deferred;
this.CreateCgPrograms();
form.Show();
while (form.Visible)
{
device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, new Color4(0.1f, 0.3f, 0.6f), 1.0f, 0);
device.BeginScene();
vertexProgram.Bind();
fragmentProgram.Bind();
/* Render the triangle. */
device.SetStreamSource(0, vertexBuffer, 0, 12);
device.VertexFormat = VertexFormat.Position;
for (int i = 0; i < MyStarCount; i++)
{
device.DrawPrimitives(PrimitiveType.TriangleFan, i * 12, 10);
}
device.EndScene();
device.Present();
Application.DoEvents();
}
fragmentProgram.Dispose();
vertexProgram.Dispose();
this.CgContext.Dispose();
foreach (var item in ObjectTable.Objects)
{
item.Dispose();
}
}
示例9: Initialize
public static void Initialize(IntPtr windowHandle)
{
handle = windowHandle;
device = new Device(new Direct3D(), 0, DeviceType.Hardware, handle, CreateFlags.SoftwareVertexProcessing, new PresentParameters()
{
//PresentationInterval = PresentInterval.One,
BackBufferWidth = 512,
BackBufferHeight = 512
});
device.SetDialogBoxMode(false);
device.SetTextureStageState(0, TextureStage.ColorOperation, TextureOperation.SelectArg1);
device.SetTextureStageState(0, TextureStage.ColorArg1, TextureArgument.Texture);
device.SetTextureStageState(0, TextureStage.ColorArg2, TextureArgument.Diffuse);
device.SetTextureStageState(0, TextureStage.AlphaOperation, TextureOperation.SelectArg1);
device.SetTextureStageState(0, TextureStage.AlphaArg1, TextureArgument.Texture);
device.SetTextureStageState(0, TextureStage.AlphaArg2, TextureArgument.Diffuse);
device.SetRenderState(RenderState.Lighting, false);
device.SetRenderState(RenderState.ZEnable, false);
device.SetRenderState(RenderState.CullMode, Cull.None);
device.SetRenderState(RenderState.SourceBlend, Blend.SourceAlpha);
device.SetRenderState(RenderState.DestinationBlend, Blend.InverseSourceAlpha);
device.SetRenderState(RenderState.AlphaBlendEnable, false);
device.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.Linear);
device.SetSamplerState(0, SamplerState.MagFilter, TextureFilter.Linear);
device.VertexFormat = VertexFormat.PositionRhw | VertexFormat.Texture1;
vertex = new VertexBuffer(device, 4 * 24, Usage.WriteOnly | Usage.Dynamic, VertexFormat.None, Pool.Default);
texture = new Texture(device, 512, 512, 1, Usage.Dynamic, Format.X8R8G8B8, Pool.Default);
device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
device.Present();
}
示例10: MainWindow
/// <summary>
/// 最上位ウインドウを作成
/// </summary>
public MainWindow()
{
// コンポーネント初期化
InitializeComponent();
// ウインドウが読み込まれたら
this.Loaded += (sender, e) =>
{
// Direct3D作成
var direct3D = new SlimDX.Direct3D9.Direct3D();
// デバイスを初期化
Device device = null;
// ティーポッドと文字列を初期化
Mesh teapod = null;
Mesh helloWorld = null;
// バッファーウインドウ作成
IntPtr handle = new HwndSource(0, 0, 0, 0, 0, "buffer", IntPtr.Zero).Handle;
// デバイスを作成
device = new Device(direct3D, 0,
DeviceType.Hardware,
handle,
CreateFlags.HardwareVertexProcessing,
new PresentParameters()
{
BackBufferFormat = Format.X8R8G8B8,
BackBufferCount = 1,
BackBufferWidth = (int)this.Width,
BackBufferHeight = (int)this.Height,
Multisample = MultisampleType.None,
SwapEffect = SwapEffect.Discard,
EnableAutoDepthStencil = true,
AutoDepthStencilFormat = Format.D16,
PresentFlags = PresentFlags.DiscardDepthStencil,
PresentationInterval = PresentInterval.Default,
Windowed = true,
DeviceWindowHandle = handle
});
// ティーポッドと文字列を作成
teapod = Mesh.CreateTeapot(device);
helloWorld = Mesh.CreateText(device, new System.Drawing.Font("Arial", 10), "Hello, world!", 0.001f, 0.001f);
// 光源描画を有効化
device.SetRenderState(RenderState.Lighting, true);
// 光源を設定
device.SetLight(0, new Light()
{
Type = LightType.Directional,
Diffuse = Color.White,
Ambient = Color.GhostWhite,
Direction = new Vector3(0.0f, -1.0f, 0.0f)
});
// 光源を有効化
device.EnableLight(0, true);
//射影変換を設定
device.SetTransform(TransformState.Projection,
Matrix.PerspectiveFovLH((float)(Math.PI / 4),
(float)(this.Width / this.Height),
0.1f, 20.0f));
//ビューを設定
device.SetTransform(TransformState.View,
Matrix.LookAtLH(new Vector3(3.0f, 2.0f, -3.0f),
Vector3.Zero,
new Vector3(0.0f, 1.0f, 0.0f)));
//マテリアル設定
device.Material = new Material()
{
Diffuse = new Color4(Color.GhostWhite)
};
// 描画される時に描画処理を実行
CompositionTarget.Rendering += (sender2, e2) =>
{
// 画像をロックしてバックバッファーに設定
this.directXImage.Lock();
this.directXImage.SetBackBuffer(D3DResourceType.IDirect3DSurface9, device.GetBackBuffer(0, 0).ComPointer);
// フロントバッファーがあれば
if (directXImage.IsFrontBufferAvailable)
{
// デバイスの現在の状態を確かめて失敗したら
if (device.TestCooperativeLevel().IsFailure)
{
// 例外
throw new Direct3D9Exception("デバイスが無効です");
}
// 全面灰色でクリア
//.........这里部分代码省略.........
示例11: RenderBezier
public void RenderBezier(ViewportInfo viewportInfo)
{
pp = new PresentParameters();
pp.SwapEffect = SwapEffect.Discard;
pp.Windowed = true;
pp.BackBufferWidth = viewportInfo.resX;
pp.BackBufferHeight = viewportInfo.resY;
pp.BackBufferFormat = Format.A8R8G8B8;
d3dBezier = new Direct3D();
deviceBezier = new Device(d3dBezier, 0, DeviceType.Hardware, handleBezier, CreateFlags.HardwareVertexProcessing, pp);
deviceBezier.SetRenderState(RenderState.Lighting, true);
deviceBezier.SetLight(0, defLight);
deviceBezier.EnableLight(0, true);
deviceBezier.SetRenderState(RenderState.FillMode, wireframe ? 2 : 0);
deviceBezier.SetRenderState(RenderState.CullMode, 1);
deviceBezier.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.FromArgb(230, 230, 230), 1.0f, 0);
deviceBezier.Present();
d3dBezier.Dispose();
deviceBezier.Dispose();
}
示例12: Main
static void Main()
{
//C#+フォームの標準準備
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//フォームの準備(SlimDXではRenderFormも使用可能)
var form = new FrmMain();// new RenderForm();
//終了イベントを捕捉
form.FormClosed += new FormClosedEventHandler(form_FormClosed);
PresentParameters pp;
//SlimDXのDeviceを準備
var device = new Device(new Direct3D(), 0, DeviceType.Hardware, form.Handle, CreateFlags.HardwareVertexProcessing, pp = new PresentParameters()
{
BackBufferWidth = form.ClientSize.Width,
BackBufferHeight = form.ClientSize.Height
});
//トゥーンテクスチャのパスを準備(SlimMMDXではトゥーンフォルダを別に用意する必要がある)
string[] toonTexPath = new string[10];
string baseDir = Path.GetDirectoryName(Application.ExecutablePath);
for (int i = 1; i <= 10; ++i)
{
toonTexPath[i - 1] = Path.Combine(baseDir, Path.Combine("toons", "toon" + i.ToString("00") + ".bmp"));
}
//SlimMMDXのセットアップ(他の機能よりも先に使用する)
SlimMMDXCore.Setup(device, toonTexPath);
//SlimMMDXCore.Instance.UsePhysics = false;
//モデルの読み込み
MMDModel model = SlimMMDXCore.Instance.LoadModelFromFile("Models/miku.pmd");
//モーションの読み込み
MMDMotion motion = SlimMMDXCore.Instance.LoadMotionFromFile("Motions/TrueMyHeart.vmd");
//モーションのセットアップ
model.AnimationPlayer.AddMotion("TrueMyHeart", motion, MMDMotionTrackOptions.UpdateWhenStopped);
//時間管理フラグ
long beforeCount = -1;
bool deviceLost = false;
//メインループ
MessagePump.Run(form, () =>
{
//経過時間を計算
float timeStep;
if (beforeCount < 0)
{
timeStep = 0.0f;
beforeCount = Stopwatch.GetTimestamp();
}
else
{
timeStep = ((float)(Stopwatch.GetTimestamp() - beforeCount)) / (float)Stopwatch.Frequency;
beforeCount = Stopwatch.GetTimestamp();
}
if (PlayFlag)
{
model.AnimationPlayer["TrueMyHeart"].Reset();
model.PhysicsManager.Reset();
model.AnimationPlayer["TrueMyHeart"].Start();
PlayFlag = false;
}
//SlimMMDXCoreのUpdate処理
SlimMMDXCore.Instance.Update(timeStep);
if (deviceLost)
{
if (device.TestCooperativeLevel() == ResultCode.DeviceNotReset)
{
device.Reset(pp);
SlimMMDXCore.Instance.OnResetDevice();
deviceLost = false;
}
}
if (!deviceLost)
{
try
{
//描画処理
device.BeginScene();
//画面のクリア
device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.CornflowerBlue, 1.0f, 0);
//モデルの描画
model.Draw();
//描画処理の終了
device.EndScene();
device.Present(Present.None);
}
catch (Direct3D9Exception e)
{
if (e.ResultCode == ResultCode.DeviceLost)
{
SlimMMDXCore.Instance.OnLostDevice();
deviceLost = true;
}
else
throw;
}
}
//速度合わせ
if (timeStep < 0.016666)
Thread.Sleep((int)(16.66666 - timeStep * 1000.0f));
});
//SlimMMDXの解放処理
foreach (var item in ObjectTable.Objects)
//.........这里部分代码省略.........