۱۱-شهریور-۱۳۸۹, ۱۴:۲۶:۵۳
مشکل این برنامه چیه همش ارور میده
کد:
Imports System.Drawing
Imports Microsoft.DirectX
Imports Microsoft.DirectX.Direct3D
Public Class Form1
Const ScreenW As Integer = 800
Const ScreenH As Integer = 600
Dim BLACK As Integer = RGB(0, 0, 0)
Dim ct As Integer
' Direct3D device variable
Dim device As Direct3D.Device
' Create a sprite handler
Dim Gameblock As Direct3D.Sprite ' the sprite
Dim GamePiece As Direct3D.Texture ' the sprite texture
' create image from a Direct3D surface
Dim image As Direct3D.Surface ' my picture
Dim backbuffer As Direct3D.Surface ' the off-screen backbuffer
Dim mTexture As Texture = Nothing
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' resize the form
Me.Size = New Size(ScreenW, ScreenH)
Me.Text = "Sprite Test"
Me.SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.Opaque, True)
' get the desktop display mode
Dim adapterNumber As Integer = Manager.Adapters.Default.Adapter
Dim mode As DisplayMode = Manager.Adapters.Default.CurrentDisplayMode
' set up the presentation parameters
Dim params As New PresentParameters
params.Windowed = True
params.SwapEffect = SwapEffect.Copy
params.AutoDepthStencilFormat = DepthFormat.D16
params.EnableAutoDepthStencil = True
params.MultiSample = MultiSampleType.None
params.BackBufferCount = 1
params.BackBufferWidth = ScreenW
params.BackBufferHeight = ScreenH
' check video card capabilities
Dim flags As CreateFlags
flags = CreateFlags.HardwareVertexProcessing
flags += CreateFlags.PureDevice
' create the Direct3D device
device = New Device(adapterNumber, DeviceType.Hardware, Me, flags, params)
' load the bitmap file
image = device.CreateOffscreenPlainSurface(ScreenW, ScreenH, Format.A8R8G8B8, Pool.Default)
SurfaceLoader.FromFile(image, "sky.bmp", fliter.None, BLACK)
' Initialize sprite object
Gameblock = New Direct3D.Sprite(device)
' Load sprite texture
GamePiece = TextureLoader.FromFile(device, "block1b.png")
Timer1.Enabled = True
End Sub
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
' check key code for ESC key
If e.KeyCode = Keys.Escape Then
' destroy the Direct3D device
device.Dispose()
' destroy the image
image.Dispose()
' end the program
End
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
' Draw the background
device.BeginScene()
' clear the back buffer
device.Clear(ClearFlags.Target + ClearFlags.ZBuffer, Color.Green, 1.0, 0)
' specify the drawing rectangles for the image
Dim Srect As New System.Drawing.Rectangle(0, 0, ScreenW, ScreenH)
Dim Drect As New System.Drawing.Rectangle(0, 0, ScreenW, ScreenH)
' get reference to the back buffer
backbuffer = device.GetBackBuffer(0, 0, BackBufferType.Mono)
' draw the image
device.StretchRectangle(image, Srect, backbuffer, Drect, 0) ' sky picture
' stop rendering
device.EndScene()
' Draw the sprite
device.BeginScene()
Gameblock.Begin(SpriteFlags.AlphaBlend)
DrawSprite()
Gameblock.End()
device.EndScene()
' copy back buffer to the screen
device.Present()
End Sub
Private Sub DrawSprite()
Dim center As New PointF(0, 0)
Dim angle As Single = 0.0
Dim position As New Point(0, 0)
Gameblock.Draw2D(GamePiece, center, angle, position, Color.White)
End Sub
End Class