⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 graphicsform.vb

📁 清华大学出版社出版的 移动应用开发宝典 张大威(2008)的附书源代码
💻 VB
字号:
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Imports Microsoft.VisualBasic
Imports Microsoft.WindowsMobile.DirectX
Imports Microsoft.WindowsMobile.DirectX.Direct3D


Module ProgramMain
    Sub Main()
        Dim frm As GraphicsForm = New GraphicsForm

        ' Initialize Direct3D
        If Not frm.Init() Then
            MessageBox.Show("Could not initialize Direct3D")
            Return
        End If

        System.Windows.Forms.Application.Run(frm)
    End Sub
End Module

Public Class GraphicsForm
    Inherits Form
    ' Our global variables for me project
    Dim DeviceForm As Device = Nothing
    Dim vertices(2) As CustomVertex.PositionColored

    Dim VBuffer As VertexBuffer = Nothing
    Dim PParameters As New PresentParameters

    ' Setup the rendering device
    Public Function Init() As Boolean
        Try
            ' We don't want to run fullscreen
            PParameters.Windowed = True
            ' Discard the frames
            PParameters.SwapEffect = SwapEffect.Discard
            'Create a DeviceForm
            DeviceForm = New Device(0, DeviceType.Default, Me, _
                CreateFlags.None, PParameters)
            'Turn off lighting
            DeviceForm.RenderState.Lighting = False

            'Create the vertices
            vertices(0).X = 0.0
            vertices(0).Y = 1.0
            vertices(0).Z = 0.0
            vertices(0).Color = System.Drawing.Color.Red.ToArgb()

            vertices(1).X = 1.0
            vertices(1).Y = -1.0
            vertices(1).Z = 0.0
            vertices(1).Color = System.Drawing.Color.Green.ToArgb()

            vertices(2).X = -1.0
            vertices(2).Y = -1.0
            vertices(2).Z = 0.0
            vertices(2).Color = System.Drawing.Color.Blue.ToArgb()

            VBuffer = New VertexBuffer( _
                            GetType(CustomVertex.PositionColored), 3, DeviceForm, 0, _
                            CustomVertex.PositionColored.Format, Pool.SystemMemory)

            VBuffer.SetData(vertices, 0, LockFlags.None)

        Catch
            ' Catch any errors and return a failure
            Return False
        End Try

        Return True
    End Function

    'All rendering for each frame occurs here
    Private Sub Render()
        If Not IsNothing(DeviceForm) Then
            'Clear the backbuffer to a white color
            DeviceForm.Clear(ClearFlags.Target, _
                System.Drawing.Color.White, 1.0F, 0)
            'Begin the scene
            DeviceForm.BeginScene()
            DeviceForm.SetStreamSource(0, VBuffer, 0)
            DeviceForm.DrawPrimitives(PrimitiveType.TriangleList, 0, 1)
            DeviceForm.EndScene()
            ' Update the screen
            DeviceForm.Present()
        Else
            'DeviceForm is has not been set
        End If
    End Sub


    'Fired when the form needs to be redrawn
    Protected Overrides Sub OnPaint( _
        ByVal e As System.Windows.Forms.PaintEventArgs)

        ' Render on painting
        Me.Render()
    End Sub

End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -