Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static RawColorBGRA lightBlue = new RawColorBGRA
- {
- R = 0x00,
- G = 0x99,
- B = 0xcc,
- A = 0x33
- };
- using System;
- using SharpDX;
- using SharpDX.Direct3D9;
- using SharpDX.Mathematics.Interop;
- namespace DirectXProject
- {
- public class DX
- {
- public Device device;
- public RawRectangle fontDimension;
- VertexBuffer vertices;
- VertexDeclaration vertexDecl;
- VertexElement[] vertexElems;
- struct Vertex
- {
- public Vector4 Position;
- public ColorBGRA Color;
- }
- public DX(IntPtr handle, int width, int height)
- {
- device = new Device(
- new Direct3D(),
- 0,
- DeviceType.Hardware,
- handle,
- CreateFlags.HardwareVertexProcessing,
- new PresentParameters(width, height));
- }
- public void RunLoop()
- {
- lock (this)
- {
- device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, DXColor.wheat, 1.0f, 0);
- device.BeginScene();
- DrawFillRectangle(vertices, 20, 20, 40, 40, DXColor.lightBlue);
- device.EndScene();
- device.Present();
- }
- }
- public void DrawFillRectangle(VertexBuffer vertices, float x1, float y1, float x2, float y2, ColorBGRA color)
- {
- vertices = new VertexBuffer(device, 4 * 20, Usage.WriteOnly, VertexFormat.None, Pool.Managed);
- vertices.Lock(0, 0, LockFlags.None).WriteRange(new[] {
- new Vertex() { Color = color, Position = new Vector4(x1, y1, 0.5f, 1.0f) },
- new Vertex() { Color = color, Position = new Vector4(x2, y1, 0.5f, 1.0f) },
- new Vertex() { Color = color, Position = new Vector4(x2, y2, 0.5f, 1.0f) },
- new Vertex() { Color = color, Position = new Vector4(x1, y2, 0.5f, 1.0f) }
- });
- vertices.Unlock();
- 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
- };
- vertexDecl = new VertexDeclaration(device, vertexElems);
- device.SetStreamSource(0, vertices, 0, 20);
- device.VertexDeclaration = vertexDecl;
- device.DrawPrimitives(PrimitiveType.TriangleFan, 0, 2);
- }
- }
- }
Add Comment
Please, Sign In to add comment