Get started with Direct3D VB.net Programming

Source: Internet
Author: User

I am a VB programmer. I have been developing database applications. After a long time, I feel bored and want to change my taste, but I have no time to learn and materials, I happened to see the learning experience written by others on CSDN, so I quickly entered the door. Good things are not exclusive. As I learned, I changed the original C # program to vb.net code, but the idea is the same and it is only for your reference.

Imports Microsoft. DirectX
Imports Microsoft. DirectX. Direct3D

Public Class Form1
Inherits System. Windows. Forms. Form

# Region "code generated by Windows Form Designer"

Public Sub New ()
MyBase. New ()

This call is required by the Windows Form Designer.
InitializeComponent ()

Add any initialization after InitializeComponent () is called
Me. SetStyle (ControlStyles. AllPaintingInWmPaint Or ControlStyles. Opaque, True)
End Sub

Form override dispose to clear the component list.
Protected Overloads Overrides Sub Dispose (ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
Components. Dispose ()
End If
End If
MyBase. Dispose (disposing)
End Sub

Required by the Windows Form Designer
Private components As System. ComponentModel. IContainer

Note: The following procedure is required by the Windows Forms designer
You can use the Windows Form Designer to modify this process.
Do not use the code editor to modify it.
<System. Diagnostics. DebuggerStepThrough ()> Private Sub InitializeComponent ()

Form1

Me. AutoScaleBaseSize = New System. Drawing. Size (6, 14)
Me. ClientSize = New System. Drawing. Size (292,266)
Me. Name = "Form1"
Me. Text = "Form1"

End Sub

# End Region


AYou posted on
Private device As Device

Public Sub InitializeGraphics ()
Set parameters
Dim presentParams As PresentParameters = New PresentParameters

PresentParams. receivwed = True window mode
PresentParams. SwapEffect = SwapEffect. Discard exchange

Create a device
Device = New Device (0, DeviceType. Hardware, Me, CreateFlags. SoftwareVertexProcessing, presentParams)
End Sub

Private Sub Form1_Load (ByVal sender As System. Object, ByVal e As System. EventArgs) Handles MyBase. Load
InitializeGraphics ()
End Sub

Protected Overrides Sub OnPaint (ByVal e As System. Windows. Forms. PaintEventArgs)
Device. Clear (ClearFlags. Target, System. Drawing. Color. CadetBlue, 1.0F, 0)

Dim verts (2) As CustomVertex. TransformedColored
Verts (0). Position = New Vector4 (Me. Width/2.0F, 50366f, 0.5F, 1.0F)
Verts (0). Color = System. Drawing. Color. Aqua. ToArgb ()
Verts (1). Position = New Vector4 (Me. Width-Me. Width/5.0F, Me. Height-Me. Height/5.0F, 0.5F, 1.0F)
Verts (1). Color = System. Drawing. Color. Black. ToArgb ()
Verts (2). Position = New Vector4 (Me. Width/5.0F, Me. Height-Me. Height/5.0F, 0.5F, 1.0F)
Verts (2). Color = System. Drawing. Color. Purple. ToArgb ()
Device. BeginScene ()
Device. VertexFormat = CustomVertex. TransformedColored. Format
Device. DrawUserPrimitives (PrimitiveType. TriangleList, 1, verts)
Device. EndScene ()
Device. Present ()

Me. Invalidate ()
End Sub
End Class


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.