විෂුවල් බේසික් මගින් DirectX8 භාවිතා කර වීඩියෝ ක්රීඩා නිපදවීම
05/29/2009 3:26 am By Chamira Jayasinghe | Articles: 7
මේ වන විට ඔබ ඩිරෙක්ට්ස් කේතනය කිරීම පිළිබඳව සාමාන්යය මට්ටමේ අවබෝධයක් නිසඟයෙන් ම ලබා ගෙන හමාර බව (ඔබ දිගටම රැඳී සිටියා නම්) ඔබට පසක් වනු ඇත. කළින් ලිපි වල දී අපි මූලිකම කරුණු සාකච්ඡා කළෙමු. රාමුවක් සකස් කරන්නේ කෙසේද? රාමුව සවි රාමුවක් කරන්නේ කෙසේද? යම් අකෂර කිහිපයක් තිරයට ලබාගන්නේ කෙසේද? යන්න පිළිබඳව අප යන්තමින් සාකච්ඡා කළෙමු. තවමත් අපි කේතනයන් සිදුවන අයුරු පිළිබඳව ගැඹුරු අධ්යයනයක් නොකළෙමු. එයට හේතු වූ කරුණ මා තව ලිපි කිහිපයකට පසුව ඔබට පසක් කර දෙන්නෙමි. යම් අයෙකු යායුතු මඟ කියා දුන් පසු ඒ මඟ තනිවම ගමන් ගන්නා පුද්ගලයා හපනෙකු බව මා පෞද්ගලිකව අදහන දෙයකි.
ශ්රී ලංකාවාසී සියළු දෙනාම සතුටින් කුල්මත් වී සිටින කාල හෝරාවේ මමත් ඔබට වර්ණවත් යමක් කියා දීමටයි මේ සැරසෙන්නේ. යම් කිසි ද්විමාන හැඩතලයකට අවනති වර්ණ කිරීමක් කරගන්නේ කෙසේ ද යන්න පිළිබඳව අපි සාකච්ඡා කරමු.
Variable Declaration Part
========================================
Option Explicit
Private Type TLVERTEX
X As Single
Y As Single
Z As Single
RHW As Single
Color As Long
Specular As Long
TU As Single
TV As Single
End Type
Private Const COLOR_DEPTH_16_BIT As Long = D3DFMT_R5G6B5
Private Const COLOR_DEPTH_24_BIT As Long = D3DFMT_A8R8G8B8
Private Const COLOR_DEPTH_32_BIT As Long = D3DFMT_X8R8G8B8
Private Const FVF_TLVERTEX As Long = D3DFVF_XYZRHW Or D3DFVF_TEX1 Or D3DFVF_DIFFUSE Or D3DFVF_SPECULAR
Private DirectX8 As DirectX8
Private Direct3D As Direct3D8
Private Direct3D_Device As Direct3DDevice8
Private Fullscreen_Enabled As Boolean
Private Running As Boolean
Private Vertex_List(3) As TLVERTEX
Private Vertex_List_2(5) As TLVERTEX
Private Vertex_List_3(5) As TLVERTEX
Private Vertex_List_4(2) As TLVERTEX
Private Function Create_TLVertex(X As Single, Y As Single, Z As Single, RHW As Single, Color As Long, Specular As Long, TU As Single, TV As Single) As TLVERTEX
Create_TLVertex.X = X
Create_TLVertex.Y = Y
Create_TLVertex.Z = Z
Create_TLVertex.RHW = RHW
Create_TLVertex.Color = Color
Create_TLVertex.Specular = Specular
Create_TLVertex.TU = TU
Create_TLVertex.TV = TV
End Function
Private Sub Form_Activate()
frmMain.Caption = "DigiT May Issue"
Dim Display_Mode As D3DDISPLAYMODE
Dim Direct3D_Window As D3DPRESENT_PARAMETERS
Set DirectX8 = New DirectX8
Set Direct3D = DirectX8.Direct3DCreate()
If Fullscreen_Enabled = True Then
Display_Mode.Width = 800
Display_Mode.Height = 600
Display_Mode.Format = COLOR_DEPTH_16_BIT
Direct3D_Window.Windowed = False
Direct3D_Window.BackBufferCount = 1
Direct3D_Window.BackBufferWidth = Display_Mode.Width
Direct3D_Window.BackBufferHeight = Display_Mode.Height
Direct3D_Window.hDeviceWindow = frmMain.hWnd
Else
Direct3D.GetAdapterDisplayMode D3DADAPTER_DEFAULT, Display_Mode
Direct3D_Window.Windowed = True
End If
Direct3D_Window.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC
Direct3D_Window.BackBufferFormat = Display_Mode.Format
Set Direct3D_Device = Direct3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, frmMain.hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, Direct3D_Window)
Vertex_List(0) = Create_TLVertex(0, 0, 0, 1, D3DColorRGBA(255, 0, 0, 0), 0, 0, 0)
Vertex_List(1) = Create_TLVertex(100, 0, 0, 1, D3DColorRGBA(0, 255, 0, 0), 0, 1, 0)
Vertex_List(2) = Create_TLVertex(0, 100, 0, 1, D3DColorRGBA(0, 0, 255, 0), 0, 0, 1)
Vertex_List(3) = Create_TLVertex(100, 100, 0, 1, D3DColorRGBA(255, 0, 255, 0), 0, 1, 1)
Vertex_List_2(0) = Create_TLVertex(120, 0, 0, 1, D3DColorRGBA(255, 0, 0, 0), 0, 0, 0)
Vertex_List_2(1) = Create_TLVertex(220, 0, 0, 1, D3DColorRGBA(0, 255, 0, 0), 0, 1, 0)
Vertex_List_2(2) = Create_TLVertex(120, 100, 0, 1, D3DColorRGBA(0, 0, 255, 0), 0, 0, 1)
Vertex_List_2(3) = Create_TLVertex(220, 0, 0, 1, D3DColorRGBA(0, 255, 0, 0), 0, 1, 0)
Vertex_List_2(4) = Create_TLVertex(220, 100, 0, 1, D3DColorRGBA(255, 0, 255, 0), 0, 1, 1)
Vertex_List_2(5) = Create_TLVertex(120, 100, 0, 1, D3DColorRGBA(0, 0, 255, 0), 0, 0, 1)
Vertex_List_3(0) = Create_TLVertex(100, 155, 0, 1, D3DColorRGBA(255, 0, 0, 0), 0, 0, 0)
Vertex_List_3(1) = Create_TLVertex(150, 105, 0, 1, D3DColorRGBA(0, 255, 0, 0), 0, 0, 0)
Vertex_List_3(2) = Create_TLVertex(250, 105, 0, 1, D3DColorRGBA(0, 0, 255, 0), 0, 0, 0)
Vertex_List_3(3) = Create_TLVertex(300, 155, 0, 1, D3DColorRGBA(255, 0, 255, 0), 0, 0, 0)
Vertex_List_3(4) = Create_TLVertex(250, 205, 0, 1, D3DColorRGBA(255, 255, 0, 0), 0, 0, 0)
Vertex_List_3(5) = Create_TLVertex(150, 205, 0, 1, D3DColorRGBA(0, 255, 255, 0), 0, 0, 0)
Vertex_List_4(0) = Create_TLVertex(0, 150, 0, 1, D3DColorRGBA(255, 0, 0, 0), 0, 0, 0)
Vertex_List_4(1) = Create_TLVertex(100, 175, 0, 1, D3DColorRGBA(0, 255, 0, 0), 0, 1, 1)
Vertex_List_4(2) = Create_TLVertex(25, 200, 0, 1, D3DColorRGBA(0, 0, 255, 0), 0, 0, 1)
Direct3D_Device.SetVertexShader FVF_TLVERTEX
Running = True
Do While Running = True
DoEvents
Direct3D_Device.Clear 0, ByVal 0, D3DCLEAR_TARGET, D3DColorRGBA(0, 0, 0, 0), 1#, 0
Direct3D_Device.BeginScene
Direct3D_Device.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex_List(0), Len(Vertex_List(0))
Direct3D_Device.DrawPrimitiveUP D3DPT_TRIANGLELIST, 2, Vertex_List_2(0), Len(Vertex_List_2(0))
Direct3D_Device.DrawPrimitiveUP D3DPT_TRIANGLEFAN, 4, Vertex_List_3(0), Len(Vertex_List_3(0))
Direct3D_Device.DrawPrimitiveUP D3DPT_TRIANGLELIST, 1, Vertex_List_4(0), Len(Vertex_List_4(0))
Direct3D_Device.EndScene
Direct3D_Device.Present ByVal 0, ByVal 0, 0, ByVal 0
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyEscape Then
Set Direct3D_Device = Nothing
Set Direct3D = Nothing
Set DirectX8 = Nothing
Unload Me
End
End If
End Sub
Private Sub Form_Load()
If MsgBox("Click Yes to go to full screen (Recommended)", vbQuestion Or vbYesNo, "Options") = vbYes Then Fullscreen_Enabled = True
End Sub
Private Sub Form_Unload(Cancel As Integer)
Running = False
Set Direct3D_Device = Nothing
Set Direct3D = Nothing
Set DirectX8 = Nothing
Unload Me
End
End Sub
මෙම කේතනය හොඳින් විමසා බලන්න. මා මෙහිදී හැඩතල 4 ක් නිර්මාණය කිරීමට පෙළඹී ඇත. ඔබ ද ඒ අයුරින් තව තවත් හැඩතල නිර්මාණයට පෙළඹෙන්න. දැනුම සොයා යන්න. ලබන ලිපියේ දී මෙම කේතනයේ සම්පූර්ණ විවරණයක් කිරීමට මා බලාපොරොත්තු වෙමි. එවිට අප විසින් ලියූ සෑම කේතනයක ම සාරාංශයක් ගම්යමාන වනු ඇත. ජය ශ්රී....



Post new comment