Directx Managed Code sample

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hello
this is simple example about how use dxmc(directx managed code).
please follow this steps
1:its seems dxmc doesnt support .netframwork4 so select 3.5.

2:after installing directx sdk add references "Microsoft.DirectX" and "Microsoft.DirectX.Direct3D" at "C:WindowsMicrosoft.NETDirectX for Managed Code1.0.2902.0".(there are other references if you need)
its done and you can write your dx program in vb

this is a simple example:

Imports Microsoft.DirectX<br/>
Imports Microsoft.DirectX.Direct3D<br/>
<br/>
<br/>
<br/>
Public Class Form1<br/>
Private angle As Single = 0.0
<br/>
Private vertices As CustomVertex.PositionColored()<br/>
Private vertices1 As CustomVertex.PositionColored()<br/>
Private vertices2 As CustomVertex.PositionColored()<br/>
Private vertices3 As CustomVertex.PositionColored()<br/>
Private device As Direct3D.Device
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load<br/>
Me.SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.Opaque, True)<br/>
Me.Height = 500<br/>
Me.Width = 500<br/>
Me.Text = "DirectX Tutorial using Visual Basic"<br/>
Initialize()<br/>
End Sub<br/>
Public Sub Initialize()<br/>
Dim present As PresentParameters = New PresentParameters<br/>
present.Windowed = True we?ll draw on a window<br/>
present.SwapEffect = SwapEffect.Discard discuss later<br/>
device = New Direct3D.Device(0, DeviceType.Hardware, Me, CreateFlags.SoftwareVertexProcessing, present)<br/>
device.Transform.Projection = Matrix.PerspectiveFovLH(CSng(Math.PI / 4), Me.Width / Me.Height, 1, 50)<br/>
device.Transform.View = Matrix.LookAtLH(New Vector3(0, 0, 30), New Vector3(0, 0, 0), New Vector3(0, 1, 0))<br/>
End Sub<br/>
Private Sub InitVertices()<br/>
vertices = New CustomVertex.PositionColored(2) {}<br/>
vertices(0).Position = New Vector3(0, 0, 0)<br/>
vertices(0).Color = Color.Red.ToArgb<br/>
vertices(1).Position = New Vector3(10, 0, 0)<br/>
vertices(1).Color = Color.Green.ToArgb<br/>
vertices(2).Position = New Vector3(5, 10, 0)<br/>
vertices(2).Color = Color.Yellow.ToArgb<br/>
<br/>
vertices1 = New CustomVertex.PositionColored(2) {}<br/>
vertices1(0).Position = New Vector3(0, 0, 0)<br/>
vertices1(0).Color = Color.Red.ToArgb<br/>
vertices1(1).Position = New Vector3(-10, 0, 0)<br/>
vertices1(1).Color = Color.Green.ToArgb<br/>
vertices1(2).Position = New Vector3(-5, -10, 0)<br/>
vertices1(2).Color = Color.Yellow.ToArgb<br/>
<br/>
vertices2 = New CustomVertex.PositionColored(2) {}<br/>
vertices2(0).Position = New Vector3(0, 0, 0)<br/>
vertices2(0).Color = Color.Red.ToArgb<br/>
vertices2(1).Position = New Vector3(-10, 0, 0)<br/>
vertices2(1).Color = Color.Green.ToArgb<br/>
vertices2(2).Position = New Vector3(5, 10, 0)<br/>
vertices2(2).Color = Color.Yellow.ToArgb<br/>
<br/>
vertices3 = New CustomVertex.PositionColored(2) {}<br/>
vertices3(0).Position = New Vector3(0, 0, 0)<br/>
vertices3(0).Color = Color.Red.ToArgb<br/>
vertices3(1).Position = New Vector3(-5, -10, 0)<br/>
vertices3(1).Color = Color.Green.ToArgb<br/>
vertices3(2).Position = New Vector3(10, 0, 0)<br/>
vertices3(2).Color = Color.Yellow.ToArgb<br/>
<br/>
End Sub<br/>
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint<br/>
InitVertices()<br/>
<br/>
device.Transform.Projection = Matrix.PerspectiveFovLH(CSng(Math.PI / 4), Me.Width / Me.Height, 1, 50)<br/>
device.Transform.View = Matrix.LookAtLH(New Vector3(0, 0, 30), New Vector3(0, 0, 0), New Vector3(0, 1, 0))<br/>
<br/>
device.RenderState.Lighting = False<br/>
device.RenderState.CullMode = Cull.None<br/>
<br/>
device.Clear(ClearFlags.Target, Color.Black, 1.0, 0)<br/>
<br/>
device.BeginScene()<br/>
device.VertexFormat = CustomVertex.PositionColored.Format<br/>
angle = angle + 0.1<br/>
device.Transform.World = Matrix.Translation(-5, -10 * 1 / 3, 0) * Matrix.RotationAxis(New Vector3(angle * 0.2, angle * 1.5, angle * 3), angle)<br/>
<br/>
device.DrawUserPrimitives(PrimitiveType.TriangleList, 1, vertices)<br/>
device.DrawUserPrimitives(PrimitiveType.TriangleList, 1, vertices1)<br/>
device.DrawUserPrimitives(PrimitiveType.TriangleList, 1, vertices2)<br/>
device.DrawUserPrimitives(PrimitiveType.TriangleList, 1, vertices3)<br/>
device.EndScene()<br/>
device.Present()<br/>
Me.Invalidate()<br/>
End Sub<br/>
<br/>
End Class
<br/>
<br/>
i hope help you


View the full article
 
Back
Top