|
|
还没到3D阶段,只是显示一张jpg图,参考了一些lights的代码和DX文档,于是写下以下代码
Private myDevice As Device = Nothing
Private PresentParameters As New Microsoft.DirectX.Direct3D.PresentParameters
Private mySwapChain As SwapChain
Private FrontSurface As Surface = Nothing '前台surface
Private BackSurface As Surface = Nothing '后台surface
Private FrontDescription As New SurfaceDescription
Private BackDescription As New SurfaceDescription
'创建Device
Public Sub CreateDevice(ByVal hd As IntPtr, ByVal FullScreenMode As Boolean)
PresentParameters.Windowed = True
PresentParameters.SwapEffect = SwapEffect.Discard
myDevice = New Device(0, DeviceType.Hardware, hd, CreateFlags.SoftwareVertexProcessing, PresentParameters)
mySwapChain = New SwapChain(myDevice, PresentParameters)
End Sub
'创建surface
Public Sub CreateSurface()
FrontDescription.Format = Format.X1R5G5B5
FrontDescription.Width = 1024
FrontDescription.Height = 768
FrontSurface = myDevice.CreateDepthStencilSurface(1024, 768, DepthFormat.D16, MultiSampleType.None, 0, True)
BackDescription.Format = Format.X1R5G5B5
BackDescription.Width = 1024
BackDescription.Height = 768
BackSurface = myDevice.CreateOffscreenPlainSurface(1024, 768, Format.X1R5G5B5, Pool.Default)
'从贴图建立材质surface
Dim TextureSurface As Surface= TextureLoader.FromFile(myDevice, "Test.jpg").GetSurfaceLevel(0)
'导入到后台surface
SurfaceLoader.FromSurface(BackSurface, New Rectangle(0, 0, 1024, 768), TextureSurface, New Rectangle(0, 0, 1024, 768), Filter.Box, Color.Red.ToArgb)
End Sub
'显示函数
Public Sub Draw()
myDevice.Clear(ClearFlag, ClearColor, 1, 0)
myDevice.BeginScene()
FrontSurface = mySwapChain.GetBackBuffer(0, BackBufferType.Mono)
myDevice.EndScene()
myDevice.Present()
End Sub
经过多次调试倒是不报什么错误了,但是调用Draw后显示的内容并不是图片Test.jpg,而是乱色块,请问我错漏了什么?
(Test.jpg是一张1024*768的16M色图片,我的电脑当前显示分辨率1024*768 16Bit色) |
|