home *** CD-ROM | disk | FTP | other *** search
/ Microsoft DirectX SDK 7.0 / Dx7.bin / DXF / samples / multimedia / vbsamples / d3dim / src / vbuffer / vertexbufferform.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-08-03  |  18.1 KB  |  501 lines

  1. VERSION 5.00
  2. Object = "{D0B8DDCE-E796-11D2-A21E-00C04F68AD33}#1.1#0"; "IMControl.ocx"
  3. Begin VB.Form vertexBufferFrm 
  4.    Caption         =   "VB Vertex Buffer Sample"
  5.    ClientHeight    =   4575
  6.    ClientLeft      =   1530
  7.    ClientTop       =   930
  8.    ClientWidth     =   4935
  9.    Icon            =   "VertexBufferForm.frx":0000
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   4575
  12.    ScaleWidth      =   4935
  13.    Begin DirectXIMControl.IMCanvas IMCanvas1 
  14.       Height          =   4575
  15.       Left            =   0
  16.       TabIndex        =   0
  17.       Top             =   0
  18.       Width           =   4935
  19.       _ExtentX        =   8705
  20.       _ExtentY        =   8070
  21.    End
  22. Attribute VB_Name = "vertexBufferFrm"
  23. Attribute VB_GlobalNameSpace = False
  24. Attribute VB_Creatable = False
  25. Attribute VB_PredeclaredId = True
  26. Attribute VB_Exposed = False
  27. Option Explicit
  28. ' Constants
  29. Const FLAG_SIZE = 10
  30. Const NUM_FLAG_VERTICES = ((FLAG_SIZE + 1) * (FLAG_SIZE + 1))
  31. Const NUM_FLAG_INDICES = (FLAG_SIZE * FLAG_SIZE * 6)
  32. Const NUM_POLE_VERTICES = 8 * 2
  33. ' Global data
  34. Dim g_iFlagIndices(NUM_FLAG_INDICES) As Integer          ' Holds index values into the following vertex array
  35. Dim g_vertPoleVertices(NUM_POLE_VERTICES) As D3DVERTEX   ' Holds vertex data for the flag
  36. Dim g_tlvertBackground(4) As D3DTLVERTEX                 ' Holds vertex data for the background
  37. Dim g_dTime As Single
  38. Dim g_bResizing As Boolean
  39. Dim g_bReadyToRender As Boolean
  40. Dim g_bRunning As Boolean
  41. Dim g_binit As Boolean
  42. ' Global D3D object variables
  43. Dim g_FlagTex As DirectDrawSurface7
  44. Dim g_BGTex As DirectDrawSurface7
  45. Dim g_VertexBuffer As Direct3DVertexBuffer7
  46. Dim g_dx As DirectX7
  47. ' Win32 Declares
  48. Private Declare Sub Sleep Lib "kernel32" (ByVal lMilliseconds As Long)
  49. Private Sub Form_Load()
  50.     If g_binit Then End
  51.     g_binit = True
  52.     On Local Error GoTo ErrorDone
  53.         
  54.     ' Set initial execution states.
  55.     g_bReadyToRender = True
  56.     g_bRunning = True
  57.     ' Initialize the canvas object.
  58.     If IMCanvas1.StartWindowed() = False Then GoTo ErrorDone
  59.     Set g_dx = IMCanvas1.dx
  60.     'create Some geometry
  61.     InitGeometry
  62.     ' Initialize Direct3D.
  63.     If InitD3D = False Then GoTo ErrorDone
  64.     g_dTime = Timer
  65.     Me.Show
  66.     Do While g_bRunning
  67.     on local error resume next
  68.         If g_bReadyToRender = True Then
  69.             UpdateFrame (Timer - g_dTime) ' Use the relative time to animate the flag.
  70.             RenderFrame
  71.             DoEvents
  72.             IMCanvas1.Update
  73.         Else
  74.             SleepUntilReady
  75.         End If
  76.     Loop
  77.     Unload Me
  78.     Exit Sub
  79. ErrorDone:
  80.     If IMCanvas1.dx.SystemBpp < 16 Then
  81.         MsgBox "This sample will only run in 16bpp color or better"
  82.         End
  83.     End If
  84.     MsgBox "Couldn't initialize the 3D scene. Terminating execution.", _
  85.         vbOKOnly, "Initialization Error."
  86.     Unload Me
  87. End Sub
  88. ' Description:
  89. '     InitD3D attempts to set up the components needed to
  90. '     display a 3D scene. It calls methods of the helper
  91. '     IMCanvas1 object to prepare for rendering in windowed
  92. '     state, and calls internal functions to setup
  93. Private Function InitD3D() As Boolean
  94.     Dim bRet As Boolean
  95.     InitD3D = True
  96.         
  97.     InitVertexBuffer
  98.     bRet = InitTextures
  99.     If bRet = False Then
  100.         Debug.Print "Could not load the texture maps, exiting application."
  101.         InitD3D = False: Exit Function
  102.     End If
  103.     InitViewportAndMaterials
  104.     ' Return a success value.
  105.     InitD3D = True
  106. End Function
  107. Private Sub InitGeometry()
  108.    Dim i As Integer, r As Integer
  109.    Dim ix As Integer, iy As Integer
  110.           
  111.    i = 0
  112.    For ix = 0 To FLAG_SIZE - 1
  113.       For iy = 0 To FLAG_SIZE - 1
  114.          g_iFlagIndices(i) = (ix + 0) + (iy + 1) * (FLAG_SIZE + 1)
  115.          g_iFlagIndices(i + 1) = (ix + 1) + (iy + 0) * (FLAG_SIZE + 1)
  116.          g_iFlagIndices(i + 2) = (ix + 0) + (iy + 0) * (FLAG_SIZE + 1)
  117.          g_iFlagIndices(i + 3) = (ix + 0) + (iy + 1) * (FLAG_SIZE + 1)
  118.          g_iFlagIndices(i + 4) = (ix + 1) + (iy + 1) * (FLAG_SIZE + 1)
  119.          g_iFlagIndices(i + 5) = (ix + 1) + (iy + 0) * (FLAG_SIZE + 1)
  120.          i = i + 6
  121.       Next iy
  122.    Next ix
  123.    For r = 0 To 7
  124.       Dim theta As Double, x As Double, z As Double
  125.       Dim vecNorm As D3DVECTOR
  126.       
  127.       theta = (r / 8) * 2 * 3.1415926283
  128.       x = Cos(theta) * 0.1
  129.       z = -Sin(theta) * 0.1
  130.       
  131.       vecNorm = MakeVector(x, 0, z)
  132.       Call g_dx.VectorNormalize(vecNorm)
  133.       g_vertPoleVertices(2 * r + 0) = MakeVertex(MakeVector(x, 10, z), vecNorm, 0, r / 7)
  134.       g_vertPoleVertices(2 * r + 1) = MakeVertex(MakeVector(x, 0, z), vecNorm, 1, r / 7)
  135.    Next r
  136.    Dim bgArray
  137.    bgArray = Array(0, 0, 0.99, 0.5, -1, 0, 0, 0.6, _
  138.                    0, 0, 0.99, 0.5, -1, 0, 1, 0, _
  139.                    0, 0, 0.99, 0.5, -1, 0, 0, 0.6, _
  140.                    0, 0, 0.99, 0.5, -1, 0, 1, 0)
  141.    ' Reuse r and i here
  142.    r = 0
  143.    For i = 0 To 3
  144.       With g_tlvertBackground(i)
  145.          .sx = bgArray(r)
  146.          .sy = bgArray(r + 1)
  147.          .sz = bgArray(r + 2)
  148.          .rhw = bgArray(r + 3)
  149.          .Color = bgArray(r + 4)
  150.          .specular = bgArray(r + 5)
  151.          .tu = bgArray(r + 6)
  152.          .tv = bgArray(r + 7)
  153.          r = r + 8
  154.       End With
  155.    Next i
  156. End Sub
  157. Private Function InitTextures() As Boolean
  158.     On Local Error GoTo TEXTURE_ERROR
  159.     FindMediaDir ("dx_logo.bmp")
  160.     With IMCanvas1
  161.         Dim bRet As Boolean
  162.         Set g_FlagTex = .CreateTextureSurface("dx_logo.bmp", D3DTEXTR_DEFAULT, 0, 0)
  163.         Set g_BGTex = .CreateTextureSurface("cloud3.bmp", D3DTEXTR_DEFAULT, 0, 0)
  164.     End With
  165.     InitTextures = True
  166.     Exit Function
  167. TEXTURE_ERROR:
  168.     Debug.Print "Could not load the texture files required for this sample. Make sure they are present in the sample directory, or in the Media folder."
  169.     InitTextures = False
  170. End Function
  171. Public Function InitVertexBuffer() As Boolean
  172.     On Local Error Resume Next
  173.     Dim d3d As Direct3D7
  174.     Dim d3dDevice As Direct3DDevice7
  175.     Set d3d = IMCanvas1.Direct3d
  176.     Set d3dDevice = IMCanvas1.Direct3DDevice
  177.     Dim VBDesc As D3DVERTEXBUFFERDESC
  178.     Dim HWDesc As D3DDEVICEDESC7, SWDesc As D3DDEVICEDESC7
  179.     InitVertexBuffer = True
  180.     '
  181.     ' Prepare the vertex buffer description.
  182.     '
  183.     VBDesc.lCaps = D3DVBCAPS_SYSTEMMEMORY
  184.     VBDesc.lFVF = D3DFVF_VERTEX
  185.     VBDesc.lNumVertices = NUM_FLAG_VERTICES
  186.     ' Create the vertex buffer.
  187.     Set g_VertexBuffer = d3d.CreateVertexBuffer(VBDesc, D3DDP_DEFAULT)
  188.     If Err.Number = D3DERR_VBUF_CREATE_FAILED Then
  189.         InitVertexBuffer = False: Exit Function
  190.     End If
  191.     '
  192.     ' Fill the buffer with vertex data.
  193.     '
  194.     With g_VertexBuffer
  195.         '   Note: You can only access the vertices in a vertex
  196.         '         buffer while it is locked.
  197.         .Lock (DDLOCK_WAIT)
  198.         
  199.         ' Prep an array to pass into the vertex buffer.
  200.         Dim Verts() As D3DVERTEX
  201.         ReDim Verts((FLAG_SIZE + 1) ^ 2)
  202.         Dim ix As Integer, iy As Integer
  203.         Dim x As Double, y As Double
  204.         Dim tu As Double, tv As Double
  205.         
  206.         For ix = 0 To FLAG_SIZE
  207.             For iy = 0 To FLAG_SIZE
  208.                 tu = ix / FLAG_SIZE
  209.                 tv = iy / FLAG_SIZE
  210.                 x = 0.2 + tu * 3.31
  211.                 y = 8# + tv * 1.82
  212.                 Verts(ix + iy * (FLAG_SIZE + 1)) = MakeVertex(MakeVector(x, y, 0), _
  213.                                                             MakeVector(0, 0, -1), _
  214.                                                             tu, 1 - tv)
  215.             Next iy
  216.         Next ix
  217.         
  218.         ' Set the vertices, then unlock the buffer.
  219.         .SetVertices 0, NUM_FLAG_VERTICES, Verts(0)
  220.         .Unlock
  221.     End With
  222. End Function
  223. Private Sub InitViewportAndMaterials()
  224.     ' D3D Objects
  225.     Dim d3dDevice As Direct3DDevice7
  226.     Dim d3d As Direct3D7
  227.     ' Locals
  228.     Dim VPDesc As D3DVIEWPORT7
  229.     Dim MatDesc As D3DMATERIAL7
  230.     Dim vecEye As D3DVECTOR
  231.     Dim vecLookAt As D3DVECTOR
  232.     Dim vecUp As D3DVECTOR
  233.     Dim matWorld As D3DMATRIX, _
  234.         matView As D3DMATRIX, _
  235.         matProj As D3DMATRIX
  236.     Dim LightDesc As D3DLIGHT7
  237.        
  238.     ' Prep object variables
  239.     Set d3dDevice = IMCanvas1.Direct3DDevice
  240.     Set d3d = IMCanvas1.Direct3d
  241.        
  242.     ' Size the background set of polygons (the ones that
  243.     ' are textured with the sky bitmap).
  244.     Call d3dDevice.GetViewport(VPDesc)
  245.       
  246.     g_tlvertBackground(0).sy = VPDesc.lHeight
  247.     g_tlvertBackground(2).sy = VPDesc.lHeight
  248.     g_tlvertBackground(2).sx = VPDesc.lWidth
  249.     g_tlvertBackground(3).sx = VPDesc.lWidth
  250.     '
  251.     ' Setup the object material
  252.     '
  253.     ' Use the global object for its shortcut color methods.
  254.     Dim dx As New DirectX7
  255.     MatDesc.Ambient = RGBAToD3DCOLORVALUE(1, 1, 1, 0)
  256.     MatDesc.diffuse = RGBAToD3DCOLORVALUE(1, 1, 1, 0)
  257.     ' Set the material properties for the device.
  258.     Call d3dDevice.SetMaterial(MatDesc)
  259.     '
  260.     ' Setup the transformation matrices.
  261.     '
  262.     vecEye = MakeVector(-1#, 7.5, -3#)
  263.     vecLookAt = MakeVector(2#, 7.5, 0#)
  264.     vecUp = MakeVector(0#, 1#, 0#)
  265.     ' Use the helper methods of the global object to create the matrices
  266.     dx.IdentityMatrix matWorld
  267.     dx.ViewMatrix matView, vecEye, vecLookAt, vecUp, 0
  268.     dx.ProjectionMatrix matProj, 1#, 100#, 3.141592 / 2#
  269.         
  270.     ' Set the transformations.
  271.     Call d3dDevice.SetTransform(D3DTRANSFORMSTATE_WORLD, matWorld)
  272.     Call d3dDevice.SetTransform(D3DTRANSFORMSTATE_VIEW, matView)
  273.     Call d3dDevice.SetTransform(D3DTRANSFORMSTATE_PROJECTION, matProj)
  274.     '
  275.     ' Setup lighting.
  276.     '
  277.     With LightDesc
  278.         .dltType = D3DLIGHT_POINT
  279.         .position = MakeVector(-1#, 8#, -2#)
  280.         .Ambient = RGBAToD3DCOLORVALUE(1#, 1#, 1#, 0#) ' The alpha component isn't used for lights.
  281.         .diffuse = RGBAToD3DCOLORVALUE(1#, 1#, 1#, 0#) ' The alpha component isn't used for lights.
  282.         .specular = RGBAToD3DCOLORVALUE(1#, 1#, 1#, 0#) ' The alpha component isn't used for lights.
  283.         .attenuation0 = 1# ' Don't attenuate the light
  284.     End With
  285.     d3dDevice.SetLight 0, LightDesc
  286.     d3dDevice.LightEnable 0, True
  287.     d3dDevice.SetRenderState D3DRENDERSTATE_LIGHTING, True
  288.     ' Set up the default texture states.
  289.     Call d3dDevice.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE)
  290.     Call d3dDevice.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE)
  291.     Call d3dDevice.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE)
  292.     Call d3dDevice.SetTextureStageState(0, D3DTSS_MINFILTER, D3DTFN_LINEAR)
  293.     Call d3dDevice.SetTextureStageState(0, D3DTSS_MAGFILTER, D3DTFG_LINEAR)
  294.     Call d3dDevice.SetRenderState(D3DRENDERSTATE_DITHERENABLE, True)
  295.     Call d3dDevice.SetRenderState(D3DRENDERSTATE_SPECULARENABLE, False)
  296.     Call d3dDevice.SetRenderState(D3DRENDERSTATE_AMBIENT, &H88888888)
  297.     Call d3dDevice.SetRenderState(D3DRENDERSTATE_ZENABLE, False)
  298.     ' Dump the global DirectX object now, it's no longer needed.
  299.     Set dx = Nothing
  300. End Sub
  301. Private Sub UpdateFrame(Time As Single)
  302.     Dim Verts(NUM_FLAG_INDICES) As D3DVERTEX
  303.     Dim ix As Integer, iy As Integer
  304.     Dim t As Single, u As Single
  305.     On Local Error Resume Next
  306.     ' Adjust the depth of each vertex in the vertex buffer, as
  307.     ' a function of time, to make the flag "wave".
  308.     With g_VertexBuffer
  309.         Call .Lock(DDLOCK_WAIT)
  310.         Call .GetVertices(0, NUM_FLAG_INDICES, Verts(0))
  311.         
  312.         For ix = 0 To FLAG_SIZE
  313.             For iy = 0 To FLAG_SIZE
  314.                 Verts(ix + iy * (FLAG_SIZE + 1)).z = ix * 0.2 * Sin(ix - Time * 6) / (FLAG_SIZE + 1)
  315.             Next iy
  316.         Next ix
  317.         
  318.         ' Set the adjusted vertices in the vertex buffer.
  319.         Call .SetVertices(0, NUM_FLAG_INDICES, Verts(0))
  320.         Call .Unlock
  321.     End With
  322.     ' Move the clouds by updating the texture coordinates
  323.     ' of the background polygons, as a function of time.
  324.     t = Time / 40!
  325.     u = ((t * 10000!) Mod 10000!) / 10000!
  326.     g_tlvertBackground(0).tu = 0 - u
  327.     g_tlvertBackground(1).tu = 0 - u
  328.     g_tlvertBackground(2).tu = 1 - u
  329.     g_tlvertBackground(3).tu = 1 - u
  330. End Sub
  331. Private Sub RenderFrame()
  332.     Dim d3dDevice As Direct3DDevice7
  333.     On Local Error Resume Next
  334.     Set d3dDevice = IMCanvas1.Direct3DDevice
  335.         
  336.     ' Clear the previous frame.
  337.     IMCanvas1.ClearBackSurface
  338.     ' Render the scene.
  339.     d3dDevice.BeginScene
  340.     If Err.Number <> 0 Then
  341.         Debug.Print "BeginScene failed."
  342.         g_bReadyToRender = False
  343.     End If
  344.     If Err.Number = 0 And g_bReadyToRender = True Then
  345.         ' Draw the background
  346.         Call d3dDevice.SetTexture(0, g_BGTex)
  347.         Call d3dDevice.DrawPrimitive(D3DPT_TRIANGLESTRIP, D3DFVF_TLVERTEX, _
  348.                                      g_tlvertBackground(0), 4, 0)
  349.                                      
  350.         Call d3dDevice.SetRenderState(141, True)
  351.         Call d3dDevice.LightEnable(0, True)
  352.         
  353.         ' Draw the pole
  354.         Call d3dDevice.DrawPrimitive(D3DPT_TRIANGLESTRIP, D3DFVF_VERTEX, _
  355.                                      g_vertPoleVertices(0), 16, 0)
  356.         
  357.         ' Draw  the flag
  358.         Call d3dDevice.SetTexture(0, g_FlagTex)
  359.         Call d3dDevice.DrawIndexedPrimitiveVB(D3DPT_TRIANGLELIST, _
  360.                                               g_VertexBuffer, _
  361.                                               0, NUM_FLAG_VERTICES, _
  362.                                               g_iFlagIndices, _
  363.                                               NUM_FLAG_INDICES, _
  364.                                               D3DDP_WAIT)
  365.     End If
  366.     ' End the scene.
  367.     d3dDevice.EndScene
  368.     If Err.Number <> 0 Then
  369.         Debug.Print "EndScene failed."
  370.         g_bReadyToRender = False
  371.     End If
  372.     Set d3dDevice = Nothing
  373. End Sub
  374. Private Function MakeVertex(posVec As D3DVECTOR, normVec As D3DVECTOR, _
  375.                             tu As Double, tv As Double) As D3DVERTEX
  376.     Dim vertOut As D3DVERTEX
  377.     With vertOut
  378.         .x = posVec.x
  379.         .y = posVec.y
  380.         .z = posVec.x
  381.         .nx = normVec.x
  382.         .ny = normVec.y
  383.         .nz = normVec.z
  384.         .tu = tu
  385.         .tv = tv
  386.     End With
  387.     MakeVertex = vertOut
  388. End Function
  389. Private Function MakeVector(a As Double, b As Double, c As Double) As D3DVECTOR
  390.     Dim vecOut As D3DVECTOR
  391.     With vecOut
  392.         .x = a
  393.         .y = b
  394.         .z = c
  395.     End With
  396.     MakeVector = vecOut
  397. End Function
  398. Private Function RGBAToD3DCOLORVALUE(r As Single, g As Single, b As Single, a As Single) As D3DCOLORVALUE
  399.     Dim c As D3DCOLORVALUE
  400.     c.r = r
  401.     c.g = g
  402.     c.b = b
  403.     c.a = a
  404.     RGBAToD3DCOLORVALUE = c
  405. End Function
  406. Sub FindMediaDir(sFile As String)
  407.     On Local Error Resume Next
  408.     If Mid$(App.Path, 2, 1) = ":" Then
  409.         ChDrive Mid$(App.Path, 1, 1)
  410.     End If
  411.     If Dir$(sFile) = "" Then
  412.          ChDir App.Path
  413.     End If
  414.     If Dir$(sFile) = "" Then
  415.         ChDir "..\media"
  416.     End If
  417.     If Dir$(sFile) = "" Then
  418.         ChDir "..\..\media"
  419.     End If
  420. End Sub
  421. Private Sub Form_Paint()
  422.     ' If the application is being resized, clear the viewport
  423.     ' to avoid graphic artifacts. Otherwise, do nothing.
  424.     If g_bResizing = True Then
  425.         IMCanvas1.ClearBackSurface
  426.     End If
  427. End Sub
  428. 'HANDLE RESIZE AND END CONDITIONS
  429. Private Sub Form_Resize()
  430.     If g_bResizing = True Then Exit Sub
  431.     g_bResizing = True
  432.     On Local Error Resume Next
  433.     IMCanvas1.Width = Me.ScaleWidth
  434.     IMCanvas1.Height = Me.ScaleHeight
  435.     Cleanup
  436.     IMCanvas1.StartWindowed
  437.     InitD3D
  438.     ' Force the Paint event to occur.
  439.     Refresh
  440.     g_bResizing = False
  441. End Sub
  442. Private Sub Form_Unload(Cancel As Integer)
  443.     ' Set the global flag to terminate the loop in Form_Load
  444.     g_bRunning = False
  445.     End
  446. End Sub
  447. ' Hang out in a sleep loop until we can restore
  448. ' our surfaces and continue rendering.
  449. Private Sub SleepUntilReady()
  450.     Debug.Print "Entered SleepUntilReady"
  451.     Dim dd As DirectDraw7
  452.     Set dd = IMCanvas1.DirectDraw
  453.     ' If the display moide changed, we can't just restore the surfaces,
  454.     ' they need to be completely recreated. Use the IMCanvas startup
  455.     ' services to reinitialize everything.
  456.      
  457.     If dd.TestCooperativeLevel = DDERR_WRONGMODE Then
  458.         Debug.Print "TestCooperativeLevel returned DDERR_WRONGMODE. Trying to recreate objects."
  459.         Set dd = Nothing
  460.         'IMCanvas1.RestoreDisplay
  461.         IMCanvas1.InitWindowed "", ""
  462.         
  463.         
  464.         ' Reinitialize Direct3D, the Vertex Buffer, and the viewport.
  465.         InitD3D
  466.         
  467.         ' Reset the reference to reflect the new DirectDraw object.
  468.         Set dd = IMCanvas1.DirectDraw
  469.     End If
  470.     While dd.TestCooperativeLevel <> DD_OK
  471.         ' While waiting for the availability of our surfaces
  472.         ' use the Sleep Win32 function to give up time slices
  473.         ' to other processes.
  474.         Debug.Print "Sleeping for 1/10th of a second. . . "
  475.         Call Sleep(100)
  476.     Wend
  477.     ' If TestCooperativeLevel returns DD_OK, the surfaces we
  478.     ' need are ready to be restored. We don't need to reload
  479.     ' their contents because we're going to overwrite the contents
  480.     ' of the render target surface; as for the bitmaps in the
  481.     ' textures, they were created as managed textures, and are
  482.     ' automatically restored and reloaded as needed by Direct3D.
  483.     Debug.Print "Restoring surfaces."
  484.     dd.RestoreAllSurfaces
  485.     ' Reset the global flag to indicate that it's ok to
  486.     ' start rendering again.
  487.     g_bReadyToRender = True
  488.     Set dd = Nothing
  489. End Sub
  490. Private Sub Cleanup()
  491.     'all surfaces must be release before resize so that the
  492.     'parent 3ddevice object can be released and a new one created
  493.     Set g_FlagTex = Nothing
  494.     Set g_BGTex = Nothing
  495.     Set g_VertexBuffer = Nothing
  496. End Sub
  497. Private Sub IMCanvas1_NewDDraw()
  498.     InitTextures
  499.     InitViewportAndMaterials
  500. End Sub
  501.