VBGood网站全文搜索 Google

搜索VBGood全站网页(全文搜索)

VB爱好者乐园(VBGood)

 找回密码
 立即注册
搜索
查看: 2942|回复: 1

诚心求教DX8.1 入门问题

[复制链接]
发表于 2015-5-22 08:39:46 | 显示全部楼层 |阅读模式
本帖最后由 苍茫 于 2015-5-22 08:41 编辑

绘制了个三角形
  1. '//******************** in modDX8 module
  2. Option Explicit

  3. Public g_DX8 As DirectX8
  4. Public g_D3D As Direct3D8
  5. Public g_D3DDevice As Direct3DDevice8
  6. Public g_VB As Direct3DVertexBuffer8


  7. Private Type CUSTOMVERTEX
  8.     x As Single         'x in screen space.
  9.     y As Single         'y in screen space.
  10.     z As Single         'normalized z.
  11.     rhw As Single       'normalized z rhw.
  12.     color As Long       'vertex color.
  13. End Type

  14. Private Const D3DFVF_CUSTOMVERTEX = (D3DFVF_XYZRHW Or D3DFVF_DIFFUSE)


  15. Public Function InitDevice(hwnd As Long) As Boolean
  16.     Set g_DX8 = New DirectX8
  17.    
  18.     'to create a Direct3D object
  19.     Set g_D3D = g_DX8.Direct3DCreate()
  20.     If g_D3D Is Nothing Then InitDevice = False: Exit Function
  21.    
  22.     'retrieve the current display mode
  23.     Dim mode As D3DDISPLAYMODE
  24.     g_D3D.GetAdapterDisplayMode D3DADAPTER_DEFAULT, mode
  25.    
  26.    
  27.     'filling in the fields of the D3DPRESENT_PARAMETERS  object
  28.     Dim d3dpp As D3DPRESENT_PARAMETERS
  29.     With d3dpp
  30.     .BackBufferFormat = mode.Format
  31.     .SwapEffect = D3DSWAPEFFECT_COPY_VSYNC
  32.     .Windowed = 1
  33.     End With
  34.    
  35.     'to use Direct3D8.CreateDevice to create the Direct3D device
  36.     Set g_D3DDevice = g_D3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, _
  37.                                      D3DCREATE_SOFTWARE_VERTEXPROCESSING, d3dpp)
  38.     If g_D3DDevice Is Nothing Then InitDevice = False: Exit Function
  39. End Function


  40. Public Sub DestroyDevice()
  41.     Set g_D3DDevice = Nothing
  42.     Set g_D3D = Nothing
  43.     Set g_DX8 = Nothing
  44.     Set g_VB = Nothing
  45. End Sub


  46. Public Sub RenderAndDisplay()
  47.     'to clear the viewport
  48.     g_D3DDevice.Clear 0, ByVal 0, D3DCLEAR_TARGET, &HFF, 1#, 0
  49.    
  50.     'begin the scene
  51.     g_D3DDevice.BeginScene
  52.    
  53.     'render the scene
  54.     Call Render
  55.     'end the scene
  56.     g_D3DDevice.EndScene
  57.    
  58.     'display it
  59.     g_D3DDevice.Present ByVal 0, ByVal 0, 0, ByVal 0

  60. End Sub

  61. Public Sub Render()
  62.     'fill three vertices with the points of a triangle
  63.     Dim Vertices(2) As CUSTOMVERTEX
  64.     With Vertices(0): .x = 150: .y = 50: .z = 0.5: .rhw = 1: .color = &HFFFF0000: End With
  65.     With Vertices(1): .x = 250: .y = 250: .z = 0.5: .rhw = 1: .color = &HFF00FF00: End With
  66.     With Vertices(2): .x = 50: .y = 250: .z = 0.5: .rhw = 1: .color = &HFF00FFFF: End With
  67.    
  68.     'create a vertex buffer as shown
  69.     Set g_VB = g_D3DDevice.CreateVertexBuffer(20 * 3, _
  70.                  0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT)
  71.     If g_VB Is Nothing Then Exit Sub
  72.    
  73.     'fill with data
  74.     D3DVertexBuffer8SetData g_VB, 0, 20 * 3, 0, Vertices(0)
  75.    
  76.     'render the scene
  77.     g_D3DDevice.SetStreamSource 0, g_VB, 20
  78.    
  79.     g_D3DDevice.SetVertexShader D3DFVF_CUSTOMVERTEX
  80.    
  81.     g_D3DDevice.DrawPrimitive D3DPT_TRIANGLELIST, 0, 1

  82. End Sub

复制代码
  1. '//****** in form1 module
  2. Option Explicit

  3. Private Sub Form_Load()
  4.     Call InitDevice(Me.hwnd)
  5.     Timer1.Interval = 40
  6. End Sub

  7. Private Sub Form_Unload(Cancel As Integer)
  8.     Call DestroyDevice
  9. End Sub

  10. Private Sub Timer1_Timer()
  11.     Call RenderAndDisplay
  12. End Sub
复制代码
怎么旋转角度呢 ?
下面这段代码 我不知道对不对,我是看MSDN, 也不清楚这段代码该插入到哪?
Dim matWorld As D3DMATRIX
D3DXMatrixRotationY matWorld, Timer * 4
g_D3DDevice.SetTransform D3DTS_WORLD, matWorld


发表于 2015-5-24 22:14:31 | 显示全部楼层
咋没人回复呢 我也想知道!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

文字版|手机版|小黑屋|VBGood  

GMT+8, 2022-7-4 04:45

VB爱好者乐园(VBGood)
快速回复 返回顶部 返回列表