本文整理汇总了C#中Device.SetLight方法的典型用法代码示例。如果您正苦于以下问题:C# Device.SetLight方法的具体用法?C# Device.SetLight怎么用?C# Device.SetLight使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Device
的用法示例。
在下文中一共展示了Device.SetLight方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Render
/// <summary>
/// シーンを描画
/// </summary>
public void Render(Device device)
{
device.Clear(ClearFlags.All, Color.Black, 1, 0);
_view.Render(device);
//ライト設定
device.SetRenderState(RenderState.Lighting, true);
foreach(var item in _lights.Select((l, i)=>new {l, i})){
device.SetLight(item.i, item.l);
device.EnableLight(item.i, true);
}
_drawables.ForEach(d => d.Draw(device));
}
示例2: LoadContent
private void LoadContent()
{
try
{
PresentParameters presentParams = new PresentParameters();
presentParams.BackBufferHeight = pictureBox.Height;
presentParams.BackBufferWidth = pictureBox.Width;
presentParams.BackBufferFormat = Format.A8R8G8B8;
presentParams.DeviceWindowHandle = pictureBox.Handle;
_direct3D = new Direct3D();
_graphigsDevice = new Device(_direct3D, 0, DeviceType.Hardware, pictureBox.Handle, CreateFlags.HardwareVertexProcessing, presentParams);
_camera.Reset(pictureBox.Width, pictureBox.Height);
_graphigsDevice.SetRenderState(RenderState.AlphaBlendEnable, true);
_graphigsDevice.SetRenderState(RenderState.SourceBlend, Blend.SourceAlpha);
_graphigsDevice.SetRenderState(RenderState.DestinationBlend, Blend.BothInverseSourceAlpha);
_graphigsDevice.SetRenderState(RenderState.Lighting, true);
_graphigsDevice.SetRenderState(RenderState.CullMode, Cull.None);
_graphigsDevice.SetRenderState(RenderState.FillMode, FillMode.Solid);
_graphigsDevice.SetRenderState(RenderState.NormalizeNormals, true);
_graphigsDevice.SetRenderState(RenderState.PointSize, 4f);
Vector3 direction = new Vector3(-1f, 0f, -1f);
direction.Normalize();
Light light = new Light();
light.Type = LightType.Directional;
light.Direction = direction;
light.Diffuse = Color.White;
light.Ambient = Color.White;
_graphigsDevice.SetLight(0, light);
_graphigsDevice.EnableLight(0, true);
direction = new Vector3(1f, 0f, 1f);
direction.Normalize();
light = new Light();
light.Type = LightType.Directional;
light.Direction = direction;
light.Diffuse = Color.White;
light.Ambient = Color.White;
_graphigsDevice.SetLight(1, light);
_graphigsDevice.EnableLight(1, true);
Material material = new Material();
material.Diffuse = Color.White;
material.Ambient = Color.Gray;
_graphigsDevice.Material = material;
_line = new Line(_graphigsDevice);
_sky = Mesh.FromFile(_graphigsDevice, @"Content\Meshes\skysphere.x", MeshFlags.Managed);
_sky.OptimizeInPlace(MeshOptimizeFlags.VertexCache | MeshOptimizeFlags.Compact | MeshOptimizeFlags.AttributeSort);
_skyTexture = Texture.FromFile(_graphigsDevice, @"Content\Textures\sky.png", Usage.None, Pool.Managed);
_colorMod = Effect.FromFile(_graphigsDevice, @"Content\Effects\Color.fx", ShaderFlags.None);
if (File.Exists(_project.MeshFilePath))
{
_mesh = LoadMesh(ref _project, true);
}
_box = Mesh.FromFile(_graphigsDevice, @"Content\Meshes\box.x", MeshFlags.Managed);
_box.OptimizeInPlace(MeshOptimizeFlags.VertexCache | MeshOptimizeFlags.Compact | MeshOptimizeFlags.AttributeSort);
_sphere = Mesh.FromFile(_graphigsDevice, @"Content\Meshes\sphere.x", MeshFlags.Managed);
_sphere.OptimizeInPlace(MeshOptimizeFlags.VertexCache | MeshOptimizeFlags.Compact | MeshOptimizeFlags.AttributeSort);
_capsuleEnd = Mesh.FromFile(_graphigsDevice, @"Content\Meshes\capsule_end.x", MeshFlags.Managed);
_capsuleEnd.OptimizeInPlace(MeshOptimizeFlags.VertexCache | MeshOptimizeFlags.Compact | MeshOptimizeFlags.AttributeSort);
_capsuleCylinder = Mesh.FromFile(_graphigsDevice, @"Content\Meshes\capsule_cylinder.x", MeshFlags.Managed);
_capsuleCylinder.OptimizeInPlace(MeshOptimizeFlags.VertexCache | MeshOptimizeFlags.Compact | MeshOptimizeFlags.AttributeSort);
_initialized = true;
}
catch (Exception e)
{
_initialized = false;
MessageBox.Show(this, e.Message);
}
}
示例3: Renderer
public Renderer(Control control)
{
PresentParameters presentParams = new PresentParameters();
presentParams.Windowed = true;
presentParams.BackBufferCount = 0;
presentParams.BackBufferWidth = Screen.PrimaryScreen.WorkingArea.Width;
presentParams.BackBufferHeight = Screen.PrimaryScreen.WorkingArea.Height;
Device = new Device(new Direct3D(), 0, DeviceType.Hardware, control.Handle, CreateFlags.SoftwareVertexProcessing, presentParams);
if ((Device.Capabilities.VertexProcessingCaps & VertexProcessingCaps.Tweening) == 0)
{
Report.ReportLog("Vertex tweening is not supported!");
}
Device.SetRenderState(RenderState.Lighting, true);
Device.SetRenderState(RenderState.DiffuseMaterialSource, ColorSource.Material);
Device.SetRenderState(RenderState.EmissiveMaterialSource, ColorSource.Material);
Device.SetRenderState(RenderState.SpecularMaterialSource, ColorSource.Material);
Device.SetRenderState(RenderState.SpecularEnable, true);
Device.SetRenderState(RenderState.AlphaBlendEnable, true);
Device.SetRenderState(RenderState.BlendOperationAlpha, BlendOperation.Add);
Device.SetRenderState(RenderState.SourceBlend, Blend.SourceAlpha);
Device.SetRenderState(RenderState.DestinationBlend, Blend.InverseSourceAlpha);
Device.SetSamplerState(0, SamplerState.MaxAnisotropy, 4);
Device.SetSamplerState(0, SamplerState.MagFilter, TextureFilter.Anisotropic);
Device.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.Anisotropic);
Device.SetSamplerState(0, SamplerState.MipFilter, TextureFilter.Linear);
Light light = new Light();
light.Type = LightType.Directional;
light.Ambient = new Color4(int.Parse((string)Gui.Config["LightAmbientARGB"], System.Globalization.NumberStyles.AllowHexSpecifier));
light.Diffuse = new Color4(int.Parse((string)Gui.Config["LightDiffuseARGB"], System.Globalization.NumberStyles.AllowHexSpecifier));
light.Specular = new Color4(int.Parse((string)Gui.Config["LightSpecularARGB"], System.Globalization.NumberStyles.AllowHexSpecifier));
Device.SetLight(0, light);
Device.EnableLight(0, true);
TextFont = new SlimDX.Direct3D9.Font(Device, new System.Drawing.Font("Arial", 8));
TextColor = new Color4(Color.White);
CursorMesh = Mesh.CreateSphere(Device, 1, 10, 10);
CursorMaterial = new Material();
CursorMaterial.Ambient = new Color4(1, 1f, 1f, 1f);
CursorMaterial.Diffuse = new Color4(1, 0.6f, 1, 0.3f);
showNormals = (bool)Gui.Config["ShowNormals"];
showBones = (bool)Gui.Config["ShowBones"];
string[] mode = Enum.GetNames(typeof(ShowBoneWeights));
for (int i = 0; i < mode.Length; i++)
{
if (mode[i] == (string)Gui.Config["ShowBoneWeights"])
{
showBoneWeights = (ShowBoneWeights)i;
break;
}
}
wireframe = (bool)Gui.Config["Wireframe"];
culling = (bool)Gui.Config["Culling"];
Background = Color.FromArgb(int.Parse((string)Gui.Config["RendererBackgroundARGB"], System.Globalization.NumberStyles.AllowHexSpecifier));
isInitialized = true;
camera = new Camera(control);
RenderControl = control;
}
示例4: init
public void init(StreamWriter st)
{
st.WriteLine("初期化開始");
pictureBox1.MouseWheel += new MouseEventHandler(pictureBox1_MouseWheel);
st.WriteLine("デバイス作成の開始");
device = new Device(new Direct3D(), 0, DeviceType.Hardware, this.pictureBox1.Handle, CreateFlags.HardwareVertexProcessing, new PresentParameters()
{
BackBufferWidth = this.pictureBox1.ClientSize.Width,
BackBufferHeight = this.pictureBox1.ClientSize.Height,
Windowed = true,
});
st.WriteLine("デバイス作成の終了");
Capabilities caps = device.Capabilities;
st.WriteLine("adapterOrdinal:" + caps.AdapterOrdinal);
st.WriteLine("DeviceType:" + caps.DeviceType);
if (caps.VertexShaderVersion.Major < 3)
{
MessageBox.Show("VertexShader3.0 以上がサポートされていません。\n現バージョン:" + caps.VertexShaderVersion);
device.Dispose();
Environment.Exit(0);
}
else if (caps.PixelShaderVersion.Major < 3)
{
MessageBox.Show("PixelShader3.0 以上がサポートされていません。\n現バージョン:" + caps.VertexShaderVersion);
device.Dispose();
Environment.Exit(0);
}
st.WriteLine("DeviceContextの初期化");
DeviceContext.init(device);
st.WriteLine("ZEnableの初期化");
device.SetRenderState(RenderState.ZEnable, true);
st.WriteLine("cameraの初期化");
camera = new Camera(device);
st.WriteLine("Floorの初期化");
floorMap = new FloorMap(device);
// teapot = Mesh.CreateTeapot(device);
// device.SetRenderState(RenderState.ShadeMode, ShadeMode.Flat);
st.WriteLine("照明の初期化");
device.SetRenderState(RenderState.Lighting, true);
device.SetLight(0, new Light() {
Type = LightType.Directional,
Diffuse = Color.White,
Ambient = Color.Gray,
Direction = new Vector3(1.0f, 1.0f, 0.0f),
});
device.EnableLight(0,true);
standardLine = new StandardLine(device);
//射影変換
device.SetTransform(TransformState.Projection,
Matrix.PerspectiveFovLH((float)(Math.PI / 4),
(float)this.pictureBox1.ClientSize.Width / (float)this.pictureBox1.ClientSize.Height,
0.1f, 1500.0f));
//ビュー
device.SetTransform(TransformState.View,
camera.getLookAtLh());
device.SetTransform(TransformState.World, Matrix.Identity);
st.WriteLine("FloorModelの初期化");
floorModel = new FloorModel(new MqoParser(device).parse(".\\projects\\sample\\model\\floor.mqo", new MqoModel()));
st.WriteLine("初期化終了");
}
示例5: GetSceneImage
public Image GetSceneImage(Scene scene)
{
RecalculateData(scene);
pp = new PresentParameters();
pp.SwapEffect = SwapEffect.Discard;
pp.Windowed = true;
pp.BackBufferWidth = 512;
pp.BackBufferHeight = 512;
pp.BackBufferFormat = Format.A8R8G8B8;
if(d3d != null)
{
d3d.Dispose();
}
if(device != null)
{
device.Dispose();
}
d3d = new Direct3D();
device = new Device(d3d, 0, DeviceType.Hardware, handle, CreateFlags.HardwareVertexProcessing, pp);
device.SetRenderState(RenderState.Lighting, true);
for(int i = scene.lights.Count; i < maxLights; ++i)
{
device.EnableLight(i, false);
}
maxLights = scene.lights.Count;
Modeler.Transformations.BoundingBox bb = new Modeler.Transformations.BoundingBox(scene);
Camera cam = new Camera();
Vector3 dir = Vector3.Normalize(bb.minBB - bb.maxBB);
cam.position = bb.maxBB - 1 * (float)Math.Sqrt((bb.minBB.x - bb.maxBB.x) * (bb.minBB.x - bb.maxBB.x) +
(bb.minBB.y - bb.maxBB.y) * (bb.minBB.y - bb.maxBB.y) + (bb.minBB.z - bb.maxBB.z) * (bb.minBB.z - bb.maxBB.z)) * dir;
cam.lookAt = bb.maxBB;
cam.fovAngle = 40;
cam.rotateAngle = 0;
Vector3 oldDir = defLight.Direction;
Vector3 dirLight = new Vector3();
dirLight.X = dir.X * (float)Math.Cos(-Math.PI / 4) + dir.Z * (float)Math.Sin(-Math.PI / 4);
dirLight.Y = dir.Y;
dirLight.Z = dir.Z * (float)Math.Cos(-Math.PI / 4) - dir.X * (float)Math.Sin(-Math.PI / 4);
dir.Normalize();
defLight.Direction = dirLight;
device.SetLight(0, defLight);
device.EnableLight(0, true);
device.SetRenderState(RenderState.FillMode, FillMode.Solid);
device.SetRenderState(RenderState.CullMode, Cull.None);
device.SetRenderState(RenderState.ShadeMode, ShadeMode.Gouraud);
Mesh mesh = numIndices >= 3 ? new Mesh(device, (int)numIndices / 3, scene.points.Count, MeshFlags.Managed | MeshFlags.Use32Bit, vertexElems) : null;
VertexBuffer vb = mesh != null ? mesh.VertexBuffer : null;
IndexBuffer ib = mesh != null ? mesh.IndexBuffer : null;
if(mesh != null)
{
vb.Lock(0, 0, LockFlags.None).WriteRange(vertices);
vb.Unlock();
ib.Lock(0, 0, LockFlags.None).WriteRange(indices, 0, (int)numIndices);
ib.Unlock();
}
Mesh selMesh = numSelIndices >= 3 ? new Mesh(device, (int)numSelIndices / 3, scene.points.Count, MeshFlags.Managed | MeshFlags.Use32Bit, vertexElems) : null;
VertexBuffer selvb = selMesh != null ? selMesh.VertexBuffer : null;
IndexBuffer selib = selMesh != null ? selMesh.IndexBuffer : null;
if(selMesh != null)
{
selvb.Lock(0, 0, LockFlags.None).WriteRange(vertices);
selvb.Unlock();
selib.Lock(0, 0, LockFlags.None).WriteRange(selIndices, 0, (int)numSelIndices);
selib.Unlock();
}
Viewport viewport = new Viewport(0, 0, 512, 512, 0, 1);
Texture texture = new Texture(device, 64, 64, 0, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default);
device.SetRenderTarget(0, texture.GetSurfaceLevel(0));
float camRotAngle = cam.rotateAngle;
float aspect = 1;
float camAngle = 2.0f * (float)Math.Atan(Math.Tan(Utilities.DegToRad(cam.fovAngle) / 2.0f) / aspect);
device.SetTransform(TransformState.View, Matrix.LookAtRH(
cam.position,
cam.lookAt,
Utilities.RotatePointAroundVector(new Vector3(0, 1, 0),
Vector3.Normalize(cam.lookAt - cam.position), camRotAngle)));
device.SetTransform(TransformState.Projection, Matrix.PerspectiveFovRH(
camAngle,
aspect,
0.01f,
//.........这里部分代码省略.........
示例6: GetBezierImage
public Image GetBezierImage(BezierSurface bezier)
{
pp = new PresentParameters();
pp.SwapEffect = SwapEffect.Discard;
pp.Windowed = true;
pp.BackBufferWidth = 512;
pp.BackBufferHeight = 512;
pp.BackBufferFormat = Format.A8R8G8B8;
if (d3dBezier != null)
{
d3dBezier.Dispose();
}
if (deviceBezier != null)
{
deviceBezier.Dispose();
}
d3dBezier = new Direct3D();
deviceBezier = new Device(d3d, 0, DeviceType.Hardware, handle, CreateFlags.HardwareVertexProcessing, pp);
deviceBezier.SetRenderState(RenderState.Lighting, true);
deviceBezier.SetLight(0, defLight);
deviceBezier.EnableLight(0, true);
deviceBezier.SetRenderState(RenderState.FillMode, FillMode.Solid);
deviceBezier.SetRenderState(RenderState.CullMode, Cull.None);
deviceBezier.SetRenderState(RenderState.ShadeMode, ShadeMode.Gouraud);
Vertex[] gridVertices = new Vertex[bezier.OutputPoints.Length];
Vertex[] controlVertices = new Vertex[bezier.ControlPoints.Length];
List<int>[] vertexTriangle = new List<int>[bezier.OutputPoints.Length];
Parallel.For(0, vertexTriangle.Length, index => vertexTriangle[index] = new List<int>());
/*for(int i = 0; i < vertexTriangle.Length; ++i)
{
vertexTriangle[i] = new List<int>();
}*/
int[] indices = new int[3 * bezier.triangles.Count];
//int[] selIndices = new int[3 * scene.triangles.Count];
uint numIndices = 0;
//uint numSelIndices = 0;
//bool[] selPoints = new bool[scene.points.Count];
//Parallel.For(0, selPoints.Length, index => selPoints[index] = false);
for (int i = 0; i < bezier.triangles.Count; i++)
{
indices[numIndices++] = (int)bezier.triangles[i].p1;
indices[numIndices++] = (int)bezier.triangles[i].p2;
indices[numIndices++] = (int)bezier.triangles[i].p3;
vertexTriangle[bezier.triangles[i].p1].Add(i);
vertexTriangle[bezier.triangles[i].p2].Add(i);
vertexTriangle[bezier.triangles[i].p3].Add(i);
}
// Liczenie normalnych siatki trojkątów
for (int i = 0; i < bezier.OutputPoints.Length; i++)
{
Vector3 normal = new Vector3();
foreach (int face in vertexTriangle[i])
{
normal += Utilities.CalculateNormal(bezier.OutputPoints[(int)bezier.triangles[face].p3], bezier.OutputPoints[(int)bezier.triangles[face].p2],
bezier.OutputPoints[(int)bezier.triangles[face].p1]);
}
normal.Normalize();
gridVertices[i].Position = new Vector3(bezier.OutputPoints[i].x, bezier.OutputPoints[i].y, bezier.OutputPoints[i].z);
gridVertices[i].Normal = normal;
gridVertices[i].Color = Color.Beige.ToArgb();
}
Mesh gridMesh = numIndices > 2 ? new Mesh(deviceBezier, (int)numIndices / 3, bezier.OutputPoints.Length, MeshFlags.Managed | MeshFlags.Use32Bit,
vertexElems) : null;
VertexBuffer vb = gridMesh != null ? gridMesh.VertexBuffer : null;
IndexBuffer ib = gridMesh != null ? gridMesh.IndexBuffer : null;
if (gridMesh != null)
{
vb.Lock(0, 0, LockFlags.None).WriteRange(gridVertices);
vb.Unlock();
ib.Lock(0, 0, LockFlags.None).WriteRange(indices, 0, (int)numIndices);
ib.Unlock();
}
Viewport viewport = new Viewport(0, 0, 512, 512, 0, 1);
Texture texture = new Texture(deviceBezier, 64, 64, 0, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default);
deviceBezier.SetRenderTarget(0, texture.GetSurfaceLevel(0));
float aspect = (float)perspective.Width / perspective.Height;
deviceBezier.SetTransform(TransformState.View, Matrix.LookAtRH(
bezierCam.position,
bezierCam.lookAt,
//.........这里部分代码省略.........
示例7: MainWindow
/// <summary>
/// 最上位ウインドウを作成
/// </summary>
public MainWindow()
{
// コンポーネント初期化
InitializeComponent();
// デバイスを作成
Device device = new Device(
new Direct3D(),
0,
DeviceType.Hardware,
IntPtr.Zero,
CreateFlags.HardwareVertexProcessing,
new PresentParameters());
// 光源を設定して有効化
device.SetLight(0, new Light()
{
Type = LightType.Directional,
Diffuse = Color.White,
Ambient = Color.GhostWhite,
Direction = new Vector3(0, -1, 1)
});
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, 2, -3),
Vector3.Zero,
new Vector3(0, 1, 0)));
//マテリアル設定
device.Material = new Material()
{
Diffuse = new Color4(Color.GhostWhite)
};
// 全面灰色でクリア
device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, new Color4(0.2f, 0.2f, 0.2f), 1.0f, 0);
// シーン開始
device.BeginScene();
//ティーポットを描画
device.SetTransform(TransformState.World,
Matrix.Translation(-3, 0, 5));
Mesh.CreateTeapot(device).DrawSubset(0);
//文字列を描画
device.SetTransform(TransformState.World,
Matrix.Translation(-4, -1, 0));
Mesh.CreateText(device, new System.Drawing.Font("Arial", 10), "Hello, world!", 0.001f, 0.001f).DrawSubset(0);
// シーン終了
device.EndScene();
// 画像をロック
this.directXImage.Lock();
// バックバッファー領域を指定
this.directXImage.SetBackBuffer(D3DResourceType.IDirect3DSurface9, device.GetBackBuffer(0, 0).ComPointer);
this.directXImage.AddDirtyRect(new Int32Rect(0, 0, directXImage.PixelWidth, directXImage.PixelHeight));
// ロック解除
this.directXImage.Unlock();
}
示例8: 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("デバイスが無効です");
}
// 全面灰色でクリア
//.........这里部分代码省略.........
示例9: 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();
}