本文整理汇总了C#中SlimDX.Draw方法的典型用法代码示例。如果您正苦于以下问题:C# SlimDX.Draw方法的具体用法?C# SlimDX.Draw怎么用?C# SlimDX.Draw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SlimDX
的用法示例。
在下文中一共展示了SlimDX.Draw方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Draw
public void Draw(SlimDX.Direct3D10.Device device, int startFace, int nFaces)
{
if (MeshType == MeshType.Indexed)
device.DrawIndexed(nFaces * 3, startFace * 3, 0);
else if (MeshType == MeshType.TriangleStrip || MeshType == MeshType.PointList || MeshType == MeshType.LineStrip)
device.Draw(NVertices, 0);
else
throw new NotImplementedException();
}
示例2: Draw
internal override void Draw(SlimDX.Direct3D11.DeviceContext context)
{
Effect effect;
using (ShaderBytecode byteCode = ShaderBytecode.CompileFromFile("Graphics/Effects/default.fx", "bidon", "fx_5_0", ShaderFlags.OptimizationLevel3, EffectFlags.None))
{
effect = new Effect(context.Device, byteCode);
}
var technique = effect.GetTechniqueByIndex(1);
var pass = technique.GetPassByIndex(0);
InputLayout inputLayout = new InputLayout(context.Device, pass.Description.Signature, new[] {
new InputElement("POSITION", 0, SlimDX.DXGI.Format.R32G32B32_Float, 0),
new InputElement("COLOR", 0, SlimDX.DXGI.Format.R8G8B8A8_UNorm, InputElement.AppendAligned, 0)
});
DataStream vertices = new DataStream((Vector3.SizeInBytes + 4) * 6, true, true);
vertices.Write(new ColoredVertex(new Vector3(1.0f, 1.0f, 0.0f), new Color4(1.0f, 0.0f, 0.0f, 0.0f).ToArgb()));
vertices.Write(new ColoredVertex(new Vector3(-1.0f, 1.0f, 0.0f), new Color4(1.0f, 0.0f, 0.0f, 0.0f).ToArgb()));
vertices.Write(new ColoredVertex(new Vector3(-1.0f, -1.0f, 0.0f), new Color4(1.0f, 0.0f, 0.0f, 0.0f).ToArgb()));
vertices.Write(new ColoredVertex(new Vector3(-1.0f, -1.0f, 0.0f), new Color4(1.0f, 0.0f, 0.0f, 0.0f).ToArgb()));
vertices.Write(new ColoredVertex(new Vector3(1.0f, 1.0f, 0.0f), new Color4(1.0f, 0.0f, 0.0f, 0.0f).ToArgb()));
vertices.Write(new ColoredVertex(new Vector3(1.0f, -1.0f, 0.0f), new Color4(1.0f, 0.0f, 0.0f, 0.0f).ToArgb()));
vertices.Position = 0;
BufferDescription bd = new BufferDescription()
{
Usage = ResourceUsage.Default,
SizeInBytes = 16 * 6,
BindFlags = BindFlags.VertexBuffer,
CpuAccessFlags = CpuAccessFlags.None
};
var vertexBuffer = new SlimDX.Direct3D11.Buffer(context.Device, vertices, bd);
context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertexBuffer, 16, 0));
//context.InputAssembler.SetIndexBuffer(indices, Format.R16_UInt, 0);
/* scale * rotation * translation */
Matrix worldMatrix = Matrix.Scaling(Scale) * Matrix.RotationYawPitchRoll(Rotation.Y, Rotation.X, Rotation.Z) * Matrix.Translation(Position);
Matrix viewMatrix = Camera.ViewMatrix;
Matrix projectionMatrix = Camera.ProjectionMatrix;
effect.GetVariableByName("finalMatrix").AsMatrix().SetMatrix(worldMatrix * viewMatrix * projectionMatrix);
context.InputAssembler.InputLayout = inputLayout;
context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleStrip;
pass.Apply(context);
context.Draw(6, 0);
}
示例3: DrawText
private void DrawText(SlimDX.Direct3D10.Font font, Vector2 pos, string text, Color4 color)
{
font.Draw(null, text, new System.Drawing.Rectangle((int)pos.X, (int)pos.Y, 0, 0), SlimDX.Direct3D10.FontDrawFlags.NoClip, color);
}
示例4: Draw
internal override void Draw(SlimDX.Direct3D11.DeviceContext context)
{
Effect effect;
using (ShaderBytecode byteCode = ShaderBytecode.CompileFromFile("Graphics/Effects/default.fx", "bidon", "fx_5_0", ShaderFlags.OptimizationLevel3, EffectFlags.None))
{
effect = new Effect(context.Device, byteCode);
}
var technique = effect.GetTechniqueByIndex(1);
var pass = technique.GetPassByIndex(0);
InputLayout inputLayout = new InputLayout(context.Device, pass.Description.Signature, new[] {
new InputElement("POSITION", 0, SlimDX.DXGI.Format.R32G32B32_Float, 0),
new InputElement("COLOR", 0, SlimDX.DXGI.Format.R8G8B8A8_UNorm, InputElement.AppendAligned, 0)
});
ColoredVertex first = default(ColoredVertex);
DataStream vertices = new DataStream((Vector3.SizeInBytes + 4) * (detail + 1), true, true);
for (int i = 0; i < detail; i++)
{
float angle = 3.14159f * 2f / detail * i;
Vector3 pos = new Vector3((float)Math.Sin(angle), (float)Math.Cos(angle), 0);
if (i == 0) first = new ColoredVertex(pos, new Color4(1.0f, 0.0f, 0.0f, 0.0f).ToArgb());
vertices.Write(new ColoredVertex(pos, new Color4(1.0f, 0.0f, 0.0f, 0.0f).ToArgb()));
// Now you fill this position into a vertexbuffer. If you don't know how to do this, the directx sdk got alot of tutorials and there are also alot available in the internet.
}
vertices.Write(first);
/*
vertices.Write(new ColoredVertex(new Vector3(1.0f, 1.0f, 0.0f), new Color4(1.0f, 0.0f, 0.0f, 0.0f).ToArgb()));
vertices.Write(new ColoredVertex(new Vector3(-1.0f, 1.0f, 0.0f), new Color4(1.0f, 0.0f, 0.0f, 0.0f).ToArgb()));
vertices.Write(new ColoredVertex(new Vector3(-1.0f, -1.0f, 0.0f), new Color4(1.0f, 0.0f, 0.0f, 0.0f).ToArgb()));
vertices.Write(new ColoredVertex(new Vector3(-1.0f, -1.0f, 0.0f), new Color4(1.0f, 0.0f, 0.0f, 0.0f).ToArgb()));
vertices.Write(new ColoredVertex(new Vector3(1.0f, 1.0f, 0.0f), new Color4(1.0f, 0.0f, 0.0f, 0.0f).ToArgb()));
vertices.Write(new ColoredVertex(new Vector3(1.0f, -1.0f, 0.0f), new Color4(1.0f, 0.0f, 0.0f, 0.0f).ToArgb()));
*/
vertices.Position = 0;
BufferDescription bd = new BufferDescription()
{
Usage = ResourceUsage.Default,
SizeInBytes = 16 * (detail + 1),
BindFlags = BindFlags.VertexBuffer,
CpuAccessFlags = CpuAccessFlags.None
};
var vertexBuffer = new SlimDX.Direct3D11.Buffer(context.Device, vertices, bd);
context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertexBuffer, 16, 0));
//context.InputAssembler.SetIndexBuffer(indices, Format.R16_UInt, 0);
/* scale * rotation * translation */
Matrix worldMatrix = Matrix.Scaling(Scale) * Matrix.RotationYawPitchRoll(Rotation.Y, Rotation.X, Rotation.Z) * Matrix.Translation(Position);
Matrix viewMatrix = Camera.ViewMatrix;
Matrix projectionMatrix = Camera.ProjectionMatrix;
effect.GetVariableByName("finalMatrix").AsMatrix().SetMatrix(worldMatrix * viewMatrix * projectionMatrix);
context.InputAssembler.InputLayout = inputLayout;
context.InputAssembler.PrimitiveTopology = PrimitiveTopology.LineStrip;
pass.Apply(context);
context.Draw(detail + 1, 0);
}