|
Zdravím, mám aplikaci založenou na článku Tomáše Hercega o DirectX (článek č. 2) zdroj je takový (jen Form1.vb):
Imports Microsoft.DirectX
Imports Microsoft.DirectX.DirectDraw
Public Class Form1
Dim src = 0
Dim dev As Device 'zařízení
Dim backBuffer As Surface, backBufferDesc As SurfaceDescription 'BackBuffer a jeho parametry
Dim frontBuffer As Surface, frontBufferDesc As SurfaceDescription 'FrontBuffer a jeho parametry
Dim clip As Clipper 'oříznutí
'surfaces
Dim Title As Surface
Dim StartGame_leave As Surface
Dim StartGame_hover As Surface
Dim HighScores_leave As Surface
Dim HighScores_hover As Surface
Dim Options_leave As Surface
Dim Options_hover As Surface
Dim Credits_leave As Surface
Dim Credits_hover As Surface
Dim QuitGame_leave As Surface
Dim QuitGame_hover As Surface
Dim Beginner_leave As Surface
Dim Beginner_hover As Surface
Dim Normal_leave As Surface
Dim Normal_hover As Surface
Dim Expert_leave As Surface
Dim Expert_hover As Surface
Dim Master_leave As Surface
Dim Master_hover As Surface
Dim TimeOut As Surface
Dim YourScore As Surface
Public Sub createDevice()
'vytvořit a nastavit zařízení
dev = New Device()
dev.SetCooperativeLevel(Me, CooperativeLevelFlags.FullscreenExclusive)
End Sub
Public Sub createBuffers()
'kontrola
If Not Me.Focused Then Exit Sub
'nastavit zařízení
dev.SetCooperativeLevel(Me, CooperativeLevelFlags.FullscreenExclusive)
'vytvořit FrontBuffer
If frontBuffer IsNot Nothing Then
frontBuffer.Restore()
Else
frontBufferDesc = New SurfaceDescription()
frontBufferDesc.SurfaceCaps.PrimarySurface = True
frontBufferDesc.SurfaceCaps.Flip = True
frontBufferDesc.SurfaceCaps.Complex = True
frontBufferDesc.BackBufferCount = 1
frontBuffer = New Surface(frontBufferDesc, dev)
End If
'vytvořit BackBuffer
If backBuffer IsNot Nothing Then
backBuffer.Restore()
Else
backBufferDesc = New SurfaceDescription()
backBufferDesc.SurfaceCaps.BackBuffer = True
backBuffer = frontBuffer.GetAttachedSurface(backBufferDesc.SurfaceCaps)
End If
'nastavit oříznutí
clip = New Clipper(dev)
clip.Window = Me
frontBuffer.Clipper = clip
End Sub
Public Sub Render()
'kontrola
If Not Me.Created Then Exit Sub
If frontBuffer Is Nothing Or backBuffer Is Nothing Then Exit Sub
If Not Me.Focused Then Exit Sub
Try
'vykreslit scénu na BackBuffer
backBuffer.ColorFill(Color.Black)
Dim bbw = backBuffer.DrawWidth
backBuffer.DrawFast(((bbw / 2) - (Title.DrawWidth / 2)), 0, Title, DrawFastFlags.SourceColorKey)
'převrátit buffery
frontBuffer.Flip(backBuffer, FlipFlags.Wait)
Catch ex As Exception
'po obnovení z minimalizace
If ex.GetType() Is GetType(SurfaceLostException) Then
createBuffers()
End If
End Try
End Sub
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
'ukončení programu
If e.KeyCode = Keys.Escape Then
End
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'vytvořit a nastavit zařízení
createDevice()
'vytvořit buffery
createBuffers()
'nahrát obsah
loadContents()
End Sub
Public Sub loadContents()
'nahrát obsah
Dim sd As New SurfaceDescription
Title = New Surface("images\Title.bmp", sd, dev)
StartGame_leave = New Surface("images\StartGame_leave.bmp", sd, dev)
StartGame_hover = New Surface("images\StartGame_hover.bmp", sd, dev)
HighScores_leave = New Surface("images\HighScores_leave.bmp", sd, dev)
HighScores_hover = New Surface("images\HighScores_hover.bmp", sd, dev)
Options_leave = New Surface("images\Options_leave.bmp", sd, dev)
Options_hover = New Surface("images\Options_hover.bmp", sd, dev)
Credits_leave = New Surface("images\Credits_leave.bmp", sd, dev)
Credits_hover = New Surface("images\Credits_hover.bmp", sd, dev)
QuitGame_leave = New Surface("images\QuitGame_leave.bmp", sd, dev)
QuitGame_hover = New Surface("images\QuitGame_hover.bmp", sd, dev)
Beginner_leave = New Surface("images\Beginner_leave.bmp", sd, dev)
Beginner_hover = New Surface("images\Beginner_hover.bmp", sd, dev)
Normal_leave = New Surface("images\Normal_leave.bmp", sd, dev)
Normal_hover = New Surface("images\Normal_hover.bmp", sd, dev)
Expert_leave = New Surface("images\Expert_leave.bmp", sd, dev)
Expert_hover = New Surface("images\Expert_hover.bmp", sd, dev)
Master_leave = New Surface("images\Master_leave.bmp", sd, dev)
Master_hover = New Surface("images\Master_hover.bmp", sd, dev)
TimeOut = New Surface("images\TimeOut.bmp", sd, dev)
YourScore = New Surface("images\YourScore.bmp", sd, dev)
End Sub
End Class
problém je, že když spustím debug, otevře se okno Form1, ale dál nic, renderer by však měl vykreslit černou orazovku a na ní nakreslit Surface Title.bmp, horizontálně do středu, vertikálně na pozici 0. Kde je zakopaný pes???? Přeji hezký den!
|