Initial commit: ROW Client source code

Game client codebase including:
- CharacterActionControl: Character and creature management
- GlobalScript: Network, items, skills, quests, utilities
- RYLClient: Main client application with GUI and event handlers
- Engine: 3D rendering engine (RYLGL)
- MemoryManager: Custom memory allocation
- Library: Third-party dependencies (DirectX, boost, etc.)
- Tools: Development utilities

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-29 16:24:34 +09:00
commit e067522598
5135 changed files with 1745744 additions and 0 deletions

View File

@@ -0,0 +1,194 @@
VERSION 5.00
Begin VB.Form Form1
Caption = "Create Device"
ClientHeight = 3195
ClientLeft = 60
ClientTop = 345
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3195
ScaleWidth = 4680
StartUpPosition = 3 'Windows Default
Begin VB.PictureBox Picture1
Height = 3015
Left = 120
ScaleHeight = 2955
ScaleWidth = 4395
TabIndex = 0
Top = 120
Width = 4455
Begin VB.Timer Timer1
Enabled = 0 'False
Interval = 40
Left = 1920
Top = 1320
End
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'-----------------------------------------------------------------------------
' File: Tut01_CreateDevice.frm
'
' Desc: This is the first tutorial for using Direct3D. In this tutorial, all
' we are doing is create a Direct3D device and using it to clear the
' screen.
' Copyright (C) 1999-2001 Microsoft Corporation. All rights reserved.
'-----------------------------------------------------------------------------
'-----------------------------------------------------------------------------
' variables
'-----------------------------------------------------------------------------
Dim g_DX As New DirectX8
Dim g_D3D As Direct3D8 'Used to create the D3DDevice
Dim g_D3DDevice As Direct3DDevice8 'Our rendering device
'-----------------------------------------------------------------------------
' Name: Form_Load()
'-----------------------------------------------------------------------------
Private Sub Form_Load()
' Allow the form to become visible
Me.Show
DoEvents
' Initialize D3D and D3DDevice
b = InitD3D(Picture1.hWnd)
If Not b Then
MsgBox "Unable to CreateDevice (see InitD3D() source for comments)"
End
End If
' Enable Timer to update
Timer1.Enabled = True
End Sub
'-----------------------------------------------------------------------------
' Name: Timer1_Timer()
'-----------------------------------------------------------------------------
Private Sub Timer1_Timer()
Render
End Sub
'-----------------------------------------------------------------------------
' Name: Form_Unload()
'-----------------------------------------------------------------------------
Private Sub Form_Unload(Cancel As Integer)
End
End Sub
'-----------------------------------------------------------------------------
' Name: InitD3D()
' Desc: Initializes Direct3D
'-----------------------------------------------------------------------------
Function InitD3D(hWnd As Long) As Boolean
On Local Error Resume Next
' Create the D3D object, which is needed to create the D3DDevice. It can
' also be used to enumerate devices types, modes, etc., which will be
' shown in a separate tutorial.
Set g_D3D = g_DX.Direct3DCreate()
If g_D3D Is Nothing Then Exit Function
' Get The current Display Mode format
Dim mode As D3DDISPLAYMODE
g_D3D.GetAdapterDisplayMode D3DADAPTER_DEFAULT, mode
' Fill in the type structure used to create the D3DDevice. Most parameters
' are left at zero. We set Windowed to 1 for TRUE, since we want to do D3D
' in a window, and the set the SwapEffect to flip the backbuffer to the
' frontbuffer only on vsync (which prevents "tearing" artifacts).
' we set the back buffer format from the current display mode
Dim d3dpp As D3DPRESENT_PARAMETERS
d3dpp.Windowed = 1
d3dpp.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC
d3dpp.BackBufferFormat = mode.Format
' Create the D3DDevice. Here we are using the default adapter (most
' systems only have one, unless they have multiple graphics hardware cards
' installed) and using the HAL (which is saying we prefer the hardware
' device or a software one). Software vertex processing is specified
' since we know it will work on all cards. On cards that support hardware
' vertex processing, though, we would see a big performance gain by using it.
'
' If you do not have hardware 3d acceleration. Enable the reference rasterizer
' using the DirectX control panel and change D3DDEVTYPE_HAL to D3DDEVTYPE_REF
Set g_D3DDevice = g_D3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, _
D3DCREATE_SOFTWARE_VERTEXPROCESSING, d3dpp)
If g_D3DDevice Is Nothing Then Exit Function
' Device state would normally be set here
InitD3D = True
End Function
'-----------------------------------------------------------------------------
' Name: Cleanup()
' Desc: Releases all previously initialized objects
'-----------------------------------------------------------------------------
Sub Cleanup()
Set g_D3DDevice = Nothing
Set g_D3D = Nothing
End Sub
'-----------------------------------------------------------------------------
' Name: Render()
' Desc: Draws the scene
'-----------------------------------------------------------------------------
Sub Render()
If g_D3DDevice Is Nothing Then Exit Sub
' Clear the backbuffer to a blue color (ARGB = 000000ff)
'
' To clear the entire back buffer we send down
' rect count = 0
' clearD3DRect = ByVal 0 (ByVal is necessary as param is of type as any)
' flags = D3DCLEAR_TARGET to specify the backbuffer
' color = &HFF& to specify BLUE (note final & indicates this is a long)
' zClear = 1 which is not used
' stencil = 0 which is not used
g_D3DDevice.Clear 0, ByVal 0, D3DCLEAR_TARGET, &HFF&, 1#, 0
' Begin the scene
g_D3DDevice.BeginScene
' Rendering of scene objects happens here
' End the scene
g_D3DDevice.EndScene
' Present the backbuffer contents to the front buffer (screen)
' parameters are flexible to allow for only showing certain
' portions of the back buffer, we want to Present the entire buffer
' so we will pass down 0 to all parameters
' SourceRect = ByVal 0 (ByVal is necessary as param is of type as any)
' DestRect = ByVal 0 (ByVal is necessary as param is of type as any)
' hWndOverride = 0 (use same hWnd as passed to CreateDevice)
' DirtyRegion = Byval 0 (ByVal is necessary as param is of type as any)
g_D3DDevice.Present ByVal 0, ByVal 0, 0, ByVal 0
End Sub

View File

@@ -0,0 +1,34 @@
Type=Exe
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#stdole2.tlb#OLE Automation
Reference=*\G{E1211242-8E94-11D1-8808-00C04FC2C603}#1.0#0#dx8vb.dll#DirectX 8 for Visual Basic Type Library
Form=Tut01_CreateDevice.frm
Startup="Form1"
Command32=""
Name="Project1"
ExeName32="vb_Tut01_CreateDevice.exe"
HelpContextID="0"
CompatibleMode="0"
MajorVer=1
MinorVer=0
RevisionVer=0
AutoIncrementVer=0
ServerSupportFiles=0
VersionCompanyName="Microsoft"
CompilationType=0
OptimizationType=0
FavorPentiumPro(tm)=0
CodeViewDebugInfo=0
NoAliasing=0
BoundsCheck=0
OverflowCheck=0
FlPointCheck=0
FDIVCheck=0
UnroundedFP=0
StartMode=0
Unattended=0
Retained=0
ThreadPerObject=0
MaxNumberOfThreads=1
[MS Transaction Server]
AutoRefresh=1

View File

@@ -0,0 +1,25 @@
//-----------------------------------------------------------------------------
// Name: CreateDevice Direct3D Tutorial
//
// Copyright (C) 1999-2001 Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
Description
===========
The CreateDevice tutorial is the first tutorial for using the new Direct3D
interfaces for DirectX 8. It shows how to create a Direct3DDevice8 object.
Path
====
Source: DXSDK\Samples\Multimedia\VBSamples\D3D\Tutorials\Tut01_CreateDevice
Programming Notes
=================
The first step of using Direct3D is creating a device. This tutorial is
so simple, that nothing is rendered with the device. The device is used
to clear the backbuffer and present the backbuffer contents, but that is
all.

View File

@@ -0,0 +1,300 @@
VERSION 5.00
Begin VB.Form Form1
BorderStyle = 1 'Fixed Single
Caption = "Vertices"
ClientHeight = 3195
ClientLeft = 45
ClientTop = 330
ClientWidth = 4680
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3195
ScaleWidth = 4680
StartUpPosition = 3 'Windows Default
Begin VB.PictureBox Picture1
Height = 3015
Left = 120
ScaleHeight = 2955
ScaleWidth = 4395
TabIndex = 0
Top = 120
Width = 4455
Begin VB.Timer Timer1
Enabled = 0 'False
Interval = 40
Left = 1920
Top = 1320
End
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'-----------------------------------------------------------------------------
' File: Tut02_Vertices.frm
'
' Desc: In this tutorial, we are rendering some vertices. This introduces the
' concept of the vertex buffer, a Direct3D object used to store
' vertices. Vertices can be defined any way we want by defining a
' custom structure and a custom FVF (flexible vertex format). In this
' tutorial, we are using vertices that are transformed (meaning they
' are already in 2D window coordinates) and lit (meaning we are not
' using Direct3D lighting, but are supplying our own colors).
'
' Copyright (C) 1999-2001 Microsoft Corporation. All rights reserved.
'-----------------------------------------------------------------------------
Option Explicit
'-----------------------------------------------------------------------------
' variables
'-----------------------------------------------------------------------------
Dim g_DX As New DirectX8
Dim g_D3D As Direct3D8 'Used to create the D3DDevice
Dim g_D3DDevice As Direct3DDevice8 'Our rendering device
Dim g_VB As Direct3DVertexBuffer8
' A structure for our custom vertex type
' representing a point on the screen
Private Type CUSTOMVERTEX
x As Single 'x in screen space
y As Single 'y in screen space
z As Single 'normalized z
rhw As Single 'normalized z rhw
color As Long 'vertex color
End Type
' Our custom FVF, which describes our custom vertex structure
Const D3DFVF_CUSTOMVERTEX = (D3DFVF_XYZRHW Or D3DFVF_DIFFUSE)
'-----------------------------------------------------------------------------
' Name: Form_Load()
'-----------------------------------------------------------------------------
Private Sub Form_Load()
Dim b As Boolean
' Allow the form to become visible
Me.Show
DoEvents
' Initialize D3D and D3DDevice
b = InitD3D(Picture1.hWnd)
If Not b Then
MsgBox "Unable to CreateDevice (see InitD3D() source for comments)"
End
End If
' Initialize Vertex Buffer
b = InitVB()
If Not b Then
MsgBox "Unable to Create VertexBuffer"
End
End If
' Enable Timer to update
Timer1.Enabled = True
End Sub
'-----------------------------------------------------------------------------
' Name: Timer1_Timer()
'-----------------------------------------------------------------------------
Private Sub Timer1_Timer()
Render
End Sub
'-----------------------------------------------------------------------------
' Name: Form_Unload()
'-----------------------------------------------------------------------------
Private Sub Form_Unload(Cancel As Integer)
End
End Sub
'-----------------------------------------------------------------------------
' Name: InitD3D()
' Desc: Initializes Direct3D
'-----------------------------------------------------------------------------
Function InitD3D(hWnd As Long) As Boolean
On Local Error Resume Next
' Create the D3D object, which is needed to create the D3DDevice. It can
' also be used to enumerate devices types, modes, etc., which will be
' shown in a separate tutorial.
Set g_D3D = g_DX.Direct3DCreate()
If g_D3D Is Nothing Then Exit Function
' get the current display mode
Dim mode As D3DDISPLAYMODE
g_D3D.GetAdapterDisplayMode D3DADAPTER_DEFAULT, mode
' Fill in the type structure used to create the D3DDevice. Most parameters
' are left at zero. We set Windowed to 1 for TRUE, since we want to do D3D
' in a window, and the set the SwapEffect to flip the backbuffer to the
' frontbuffer only on vsync (which prevents "tearing" artifacts).
' Use the same format as the current display mode
Dim d3dpp As D3DPRESENT_PARAMETERS
d3dpp.Windowed = 1
d3dpp.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC
d3dpp.BackBufferFormat = mode.Format
' Create the D3DDevice. Here we are using the default adapter (most
' systems only have one, unless they have multiple graphics hardware cards
' installed) and using the HAL (which is saying we prefer the hardware
' device or a software one). Software vertex processing is specified
' since we know it will work on all cards. On cards that support hardware
' vertex processing, though, we would see a big performance gain by using it.
'
' If you do not have hardware 3d acceleration. Enable the reference rasterizer
' using the DirectX control panel and change D3DDEVTYPE_HAL to D3DDEVTYPE_REF
Set g_D3DDevice = g_D3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, _
D3DCREATE_SOFTWARE_VERTEXPROCESSING, d3dpp)
If g_D3DDevice Is Nothing Then Exit Function
' Device state would normally be set here
InitD3D = True
End Function
'-----------------------------------------------------------------------------
' Name: InitVB()
' Desc: Creates a vertex buffer and fills it with our vertices. The vertex
' buffer is basically just a chuck of memory that holds vertices. After
' creating it, we must D3DVertexBuffer8SetData to fill it. For indices,
' D3D also uses index buffers. The special thing about vertex and index
' buffers is that they can be created in device memory, allowing some
' cards to process them in hardware, resulting in a dramatic
' performance gain.
'-----------------------------------------------------------------------------
Function InitVB() As Boolean
' Initialize three vertices for rendering a triangle
Dim Vertices(2) As CUSTOMVERTEX
Dim VertexSizeInBytes As Long
VertexSizeInBytes = Len(Vertices(0))
With Vertices(0): .x = 150: .y = 50: .z = 0.5: .rhw = 1: .color = &HFFFF0000: End With
With Vertices(1): .x = 250: .y = 250: .z = 0.5: .rhw = 1: .color = &HFF00FF00: End With
With Vertices(2): .x = 50: .y = 250: .z = 0.5: .rhw = 1: .color = &HFF00FFFF: End With
' Create the vertex buffer. Here we are allocating enough memory
' (from the default pool) to hold all our 3 custom vertices. We also
' specify the FVF, so the vertex buffer knows what data it contains.
' LengthInBytes= VertexSizeInBytes *3 (For total size of our buffer)
' fvf=D3DFVF_CUSTOMVERTEX (Describes whats in our vertex)
' flags= 0 (default)
' pool=D3DPOOL_DEFAULT (Let d3d decide what kind of memory)
Set g_VB = g_D3DDevice.CreateVertexBuffer(VertexSizeInBytes * 3, _
0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT)
If g_VB Is Nothing Then Exit Function
' Now we fill the vertex buffer. To do this in Visual Basic we will use the
' D3DVertexBuffer8SetData helper function. It locks the vertex buffer
' copys data in and then unlocks the surface all with one call
' VBuffer=g_VB The vertex buffer we want to fill
' Offset=0 We want to fill from the start of the buffer
' Size=VertSizeInBytes*3 Copy 3 CUSTOMVERTEX types into the buffer
' flags=0 Send default flags to the lock
' data=Vertices(0) This param is as any
' To use it we send the first element
' in our array
D3DVertexBuffer8SetData g_VB, 0, VertexSizeInBytes * 3, 0, Vertices(0)
InitVB = True
End Function
'-----------------------------------------------------------------------------
' Name: Cleanup()
' Desc: Releases all previously initialized objects
'-----------------------------------------------------------------------------
Sub Cleanup()
Set g_VB = Nothing
Set g_D3DDevice = Nothing
Set g_D3D = Nothing
End Sub
'-----------------------------------------------------------------------------
' Name: Render()
' Desc: Draws the scene
'-----------------------------------------------------------------------------
Sub Render()
Dim v As CUSTOMVERTEX
Dim sizeOfVertex As Long
If g_D3DDevice Is Nothing Then Exit Sub
' Clear the backbuffer to a blue color (ARGB = 000000ff)
'
' To clear the entire back buffer we send down
' rect count = 0
' clearD3DRect = ByVal 0 (ByVal is necessary as param is of type as any)
' flags = D3DCLEAR_TARGET to specify the backbuffer
' color = &HFF& to specify BLUE (note final & indicates this is a long)
' zClear = 1 which is not used
' stencil = 0 which is not used
g_D3DDevice.Clear 0, ByVal 0, D3DCLEAR_TARGET, &HFF&, 1#, 0
' Begin the scene
g_D3DDevice.BeginScene
'Draw the triangles in the vertex buffer. This is broken into a few
' steps. We are passing the vertices down a "stream", so first we need
' to specify the source of that stream, which is our vertex buffer. Then
' we need to let D3D know what vertex shader to use. Full, custom vertex
' shaders are an advanced topic, but in most cases the vertex shader is
' just the FVF, so that D3D knows what type of vertices we are dealing
' with. Finally, we call DrawPrimitive() which does the actual rendering
' of our geometry (in this case, just one triangle).
sizeOfVertex = Len(v)
g_D3DDevice.SetStreamSource 0, g_VB, sizeOfVertex
g_D3DDevice.SetVertexShader D3DFVF_CUSTOMVERTEX
g_D3DDevice.DrawPrimitive D3DPT_TRIANGLELIST, 0, 1
' End the scene
g_D3DDevice.EndScene
' Present the backbuffer contents to the front buffer (screen)
' parameters are flexible to allow for only showing certain
' portions of the back buffer, we want to Present the entire buffer
' so we will pass down 0 to all parameters
' SourceRect = ByVal 0 (ByVal is necessary as param is of type as any)
' DestRect = ByVal 0 (ByVal is necessary as param is of type as any)
' hWndOverride = 0 (use same hWnd as passed to CreateDevice)
' DirtyRegion = Byval 0 (ByVal is necessary as param is of type as any)
g_D3DDevice.Present ByVal 0, ByVal 0, 0, ByVal 0
End Sub

View File

@@ -0,0 +1,34 @@
Type=Exe
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#stdole2.tlb#OLE Automation
Reference=*\G{E1211242-8E94-11D1-8808-00C04FC2C603}#1.0#0#dx8vb.dll#DirectX 8 for Visual Basic Type Library
Form=Tut02_vertices.frm
Startup="Form1"
Command32=""
Name="Project1"
ExeName32="vb_Tut02_Vertices.exe"
HelpContextID="0"
CompatibleMode="0"
MajorVer=1
MinorVer=0
RevisionVer=0
AutoIncrementVer=0
ServerSupportFiles=0
VersionCompanyName="Microsoft"
CompilationType=0
OptimizationType=0
FavorPentiumPro(tm)=0
CodeViewDebugInfo=0
NoAliasing=0
BoundsCheck=0
OverflowCheck=0
FlPointCheck=0
FDIVCheck=0
UnroundedFP=0
StartMode=0
Unattended=0
Retained=0
ThreadPerObject=0
MaxNumberOfThreads=1
[MS Transaction Server]
AutoRefresh=1

View File

@@ -0,0 +1,27 @@
//-----------------------------------------------------------------------------
// Name: Vertices Direct3D Tutorial
//
// Copyright (C) 1999-2001 Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
Description
===========
The Vertices tutorial demonstrates the necessary API to render vertices
using Direct3D.
Path
====
Source: DXSDK\Samples\Multimedia\VBSamples\D3D\Tutorials\Tut02_Vertices
Programming Notes
=================
To render geometry in Direct3D, a vertex buffer must be created and filled
with vertices that described the geometry. Vertices can have many components
including positions, normals, blend weights, colors, and texture
coordinates. This simple tutorial uses vertices with only positions and
colors. The important parts of the tutorial are vertex buffer creation,
locking and filling the vertex buffer, and rendering the vertex buffer.

View File

@@ -0,0 +1,313 @@
VERSION 5.00
Begin VB.Form Form1
BorderStyle = 1 'Fixed Single
Caption = "Matrices"
ClientHeight = 3195
ClientLeft = 45
ClientTop = 330
ClientWidth = 4680
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3195
ScaleWidth = 4680
StartUpPosition = 3 'Windows Default
Begin VB.PictureBox Picture1
Height = 3015
Left = 120
ScaleHeight = 2955
ScaleWidth = 4395
TabIndex = 0
Top = 120
Width = 4455
Begin VB.Timer Timer1
Enabled = 0 'False
Interval = 40
Left = 1920
Top = 1320
End
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'-----------------------------------------------------------------------------
' File: Tut03_Matrices.frm
'
'
' Desc: Now that we know how to create a device and render some 2D vertices,
' this tutorial goes the next step and renders 3D geometry. To deal with
' 3D geometry we need to introduce the use of 4x4 matrices to transform
' the geometry with translations, rotations, scaling, and setting up our
' camera.
'
' Geometry is defined in model space. We can move it (translation),
' rotate it (rotation), or stretch it (scaling) using a world transform.
' The geometry is then said to be in world space. Next, we need to
' position the camera, or eye point, somewhere to look at the geometry.
' Another transform, via the view matrix, is used, to position and
' rotate our view. With the geometry then in view space, our last
' transform is the projection transform, which "projects" the 3D scene
' into our 2D viewport.
'
' Note that in this tutorial, we are introducing the use of D3DX, which
' is a set up helper utilities for D3D. In this case, we are using some
' of D3DX's useful matrix initialization functions.
'
' Copyright (C) 1999-2001 Microsoft Corporation. All rights reserved.
'-----------------------------------------------------------------------------
Option Explicit
'-----------------------------------------------------------------------------
' variables
'-----------------------------------------------------------------------------
Dim g_DX As New DirectX8
Dim g_D3D As Direct3D8 'Used to create the D3DDevice
Dim g_D3DDevice As Direct3DDevice8 'Our rendering device
Dim g_VB As Direct3DVertexBuffer8
' A structure for our custom vertex type
' representing a point on the screen
Private Type CUSTOMVERTEX
x As Single 'x in screen space
y As Single 'y in screen space
z As Single 'normalized z
color As Long 'vertex color
End Type
' Our custom FVF, which describes our custom vertex structure
Const D3DFVF_CUSTOMVERTEX = (D3DFVF_XYZ Or D3DFVF_DIFFUSE)
Const g_pi = 3.1415
'-----------------------------------------------------------------------------
' Name: Form_Load()
'-----------------------------------------------------------------------------
Private Sub Form_Load()
Dim b As Boolean
' Allow the form to become visible
Me.Show
DoEvents
' Initialize D3D and D3DDevice
b = InitD3D(Picture1.hWnd)
If Not b Then
MsgBox "Unable to CreateDevice (see InitD3D() source for comments)"
End
End If
' Initialize Vertex Buffer with Geometry
b = InitGeometry()
If Not b Then
MsgBox "Unable to Create VertexBuffer"
End
End If
' Enable Timer to update
Timer1.Enabled = True
End Sub
'-----------------------------------------------------------------------------
' Name: Timer1_Timer()
'-----------------------------------------------------------------------------
Private Sub Timer1_Timer()
Render
End Sub
'-----------------------------------------------------------------------------
' Name: Form_Unload()
'-----------------------------------------------------------------------------
Private Sub Form_Unload(Cancel As Integer)
End
End Sub
'-----------------------------------------------------------------------------
' Name: InitD3D()
' Desc: Initializes Direct3D
'-----------------------------------------------------------------------------
Function InitD3D(hWnd As Long) As Boolean
On Local Error Resume Next
' Create the D3D object
Set g_D3D = g_DX.Direct3DCreate()
If g_D3D Is Nothing Then Exit Function
' Get the current display mode
Dim mode As D3DDISPLAYMODE
g_D3D.GetAdapterDisplayMode D3DADAPTER_DEFAULT, mode
' Fill in the type structure used to create the device
Dim d3dpp As D3DPRESENT_PARAMETERS
d3dpp.Windowed = 1
d3dpp.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC
d3dpp.BackBufferFormat = mode.Format
' Create the D3DDevice
' If you do not have hardware 3d acceleration. Enable the reference rasterizer
' using the DirectX control panel and change D3DDEVTYPE_HAL to D3DDEVTYPE_REF
Set g_D3DDevice = g_D3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, _
D3DCREATE_SOFTWARE_VERTEXPROCESSING, d3dpp)
If g_D3DDevice Is Nothing Then Exit Function
' Device state would normally be set here
' Turn off culling, so we see the front and back of the triangle
g_D3DDevice.SetRenderState D3DRS_CULLMODE, D3DCULL_NONE
' Turn off D3D lighting, since we are providing our own vertex colors
g_D3DDevice.SetRenderState D3DRS_LIGHTING, 0
InitD3D = True
End Function
'-----------------------------------------------------------------------------
' Name: SetupMatrices()
' Desc: Sets up the world, view, and projection transform matrices.
'-----------------------------------------------------------------------------
Sub SetupMatrices()
' The transform Matrix is used to position and orient the objects
' you are drawing
' For our world matrix, we will just rotate the object about the y-axis.
Dim matWorld As D3DMATRIX
D3DXMatrixRotationY matWorld, Timer * 4
g_D3DDevice.SetTransform D3DTS_WORLD, matWorld
' The view matrix defines the position and orientation of the camera
' Set up our view matrix. A view matrix can be defined given an eye point,
' a point to lookat, and a direction for which way is up. Here, we set the
' eye five units back along the z-axis and up three units, look at the
' origin, and define "up" to be in the y-direction.
Dim matView As D3DMATRIX
D3DXMatrixLookAtLH matView, vec3(0#, 3#, -5#), _
vec3(0#, 0#, 0#), _
vec3(0#, 1#, 0#)
g_D3DDevice.SetTransform D3DTS_VIEW, matView
' The projection matrix describes the camera's lenses
' For the projection matrix, we set up a perspective transform (which
' transforms geometry from 3D view space to 2D viewport space, with
' a perspective divide making objects smaller in the distance). To build
' a perpsective transform, we need the field of view (1/4 pi is common),
' the aspect ratio, and the near and far clipping planes (which define at
' what distances geometry should be no longer be rendered).
Dim matProj As D3DMATRIX
D3DXMatrixPerspectiveFovLH matProj, g_pi / 4, 1, 1, 1000
g_D3DDevice.SetTransform D3DTS_PROJECTION, matProj
End Sub
'-----------------------------------------------------------------------------
' Name: InitGeometry()
' Desc: Creates a vertex buffer and fills it with our vertices.
'-----------------------------------------------------------------------------
Function InitGeometry() As Boolean
' Initialize three vertices for rendering a triangle
Dim Vertices(2) As CUSTOMVERTEX
Dim VertexSizeInBytes As Long
VertexSizeInBytes = Len(Vertices(0))
With Vertices(0): .x = -1: .y = -1: .z = 0: .color = &HFFFF0000: End With
With Vertices(1): .x = 1: .y = -1: .z = 0: .color = &HFF00FF00: End With
With Vertices(2): .x = 0: .y = 1: .z = 0: .color = &HFF00FFFF: End With
' Create the vertex buffer.
Set g_VB = g_D3DDevice.CreateVertexBuffer(VertexSizeInBytes * 3, _
0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT)
If g_VB Is Nothing Then Exit Function
' fill the vertex buffer from our array
D3DVertexBuffer8SetData g_VB, 0, VertexSizeInBytes * 3, 0, Vertices(0)
InitGeometry = True
End Function
'-----------------------------------------------------------------------------
' Name: Cleanup()
' Desc: Releases all previously initialized objects
'-----------------------------------------------------------------------------
Sub Cleanup()
Set g_VB = Nothing
Set g_D3DDevice = Nothing
Set g_D3D = Nothing
End Sub
'-----------------------------------------------------------------------------
' Name: Render()
' Desc: Draws the scene
'-----------------------------------------------------------------------------
Sub Render()
Dim v As CUSTOMVERTEX
Dim sizeOfVertex As Long
If g_D3DDevice Is Nothing Then Exit Sub
' Clear the backbuffer to a blue color (ARGB = 000000ff)
'
' To clear the entire back buffer we send down
g_D3DDevice.Clear 0, ByVal 0, D3DCLEAR_TARGET, &HFF&, 1#, 0
' Begin the scene
g_D3DDevice.BeginScene
' Setup the world, view, and projection matrices
SetupMatrices
'Draw the triangles in the vertex buffer
sizeOfVertex = Len(v)
g_D3DDevice.SetStreamSource 0, g_VB, sizeOfVertex
g_D3DDevice.SetVertexShader D3DFVF_CUSTOMVERTEX
g_D3DDevice.DrawPrimitive D3DPT_TRIANGLELIST, 0, 1
' End the scene
g_D3DDevice.EndScene
' Present the backbuffer contents to the front buffer (screen)
g_D3DDevice.Present ByVal 0, ByVal 0, 0, ByVal 0
End Sub
'-----------------------------------------------------------------------------
' Name: vec3()
' Desc: helper function
'-----------------------------------------------------------------------------
Function vec3(x As Single, y As Single, z As Single) As D3DVECTOR
vec3.x = x
vec3.y = y
vec3.z = z
End Function

View File

@@ -0,0 +1,34 @@
Type=Exe
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#stdole2.tlb#OLE Automation
Reference=*\G{E1211242-8E94-11D1-8808-00C04FC2C603}#1.0#0#dx8vb.dll#DirectX 8 for Visual Basic Type Library
Form=Tut03_matrices.frm
Startup="Form1"
Command32=""
Name="Project1"
ExeName32="vb_Tut03_Matrices.exe"
HelpContextID="0"
CompatibleMode="0"
MajorVer=1
MinorVer=0
RevisionVer=0
AutoIncrementVer=0
ServerSupportFiles=0
VersionCompanyName="Microsoft"
CompilationType=0
OptimizationType=0
FavorPentiumPro(tm)=0
CodeViewDebugInfo=0
NoAliasing=0
BoundsCheck=0
OverflowCheck=0
FlPointCheck=0
FDIVCheck=0
UnroundedFP=0
StartMode=0
Unattended=0
Retained=0
ThreadPerObject=0
MaxNumberOfThreads=1
[MS Transaction Server]
AutoRefresh=1

View File

@@ -0,0 +1,29 @@
//-----------------------------------------------------------------------------
// Name: Matrices Direct3D Tutorial
//
// Copyright (C) 1999-2001 Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
Description
===========
The Matrices tutorial shows how to use 4x4 matrices to transform vertices
in Direct3D.
Path
====
Source: DXSDK\Samples\Multimedia\VBSamples\D3D\Tutorials\Tut03_Matrices
Programming Notes
=================
To render vertices in 3D, certain mathematical transformations must be
performed on the vertices. This includes the world transform (which
translates, rotates, and scales the geometry), the view transform (which
orients the camera, or view) and the projection transform (which projects
the 3D scene into 2D viewport). Transforms are represented mathematically
as 4x4 matrices. This tutorial introdcues the use of the D3DX helper
library, which contains (amongst other things) functions to build and
manipulate our 4x4 tranform matrices.

View File

@@ -0,0 +1,373 @@
VERSION 5.00
Begin VB.Form Form1
BorderStyle = 1 'Fixed Single
Caption = "Lights"
ClientHeight = 3195
ClientLeft = 45
ClientTop = 330
ClientWidth = 4680
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3195
ScaleWidth = 4680
StartUpPosition = 3 'Windows Default
Begin VB.PictureBox Picture1
Height = 3015
Left = 120
ScaleHeight = 2955
ScaleWidth = 4395
TabIndex = 0
Top = 120
Width = 4455
Begin VB.Timer Timer1
Enabled = 0 'False
Interval = 40
Left = 1920
Top = 1320
End
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'-----------------------------------------------------------------------------
' File: Tut04_lights.frm
'
'
' Desc: Rendering 3D geometry is much more interesting when dynamic lighting
' is added to the scene. To use lighting in D3D, you must create one or
' lights, setup a material, and make sure your geometry contains surface
' normals. Lights may have a position, a color, and be of a certain type
' such as directional (light comes from one direction), point (light
' comes from a specific x,y,z coordinate and radiates in all directions)
' or spotlight. Materials describe the surface of your geometry,
' specifically, how it gets lit (diffuse color, ambient color, etc.).
' Surface normals are part of a vertex, and are needed for the D3D's
' internal lighting calculations.
'
' Copyright (C) 1999-2001 Microsoft Corporation. All rights reserved.
'-----------------------------------------------------------------------------
Option Explicit
'-----------------------------------------------------------------------------
' variables
'-----------------------------------------------------------------------------
Dim g_DX As New DirectX8
Dim g_D3D As Direct3D8 'Used to create the D3DDevice
Dim g_D3DDevice As Direct3DDevice8 'Our rendering device
Dim g_VB As Direct3DVertexBuffer8
' A structure for our custom vertex type
Private Type CUSTOMVERTEX
postion As D3DVECTOR '3d position for vertex
normal As D3DVECTOR 'surface normal for vertex
End Type
' Our custom FVF, which describes our custom vertex structure
Const D3DFVF_CUSTOMVERTEX = (D3DFVF_XYZ Or D3DFVF_NORMAL)
Const g_pi = 3.1415
'-----------------------------------------------------------------------------
' Name: Form_Load()
'-----------------------------------------------------------------------------
Private Sub Form_Load()
Dim b As Boolean
' Allow the form to become visible
Me.Show
DoEvents
' Initialize D3D and D3DDevice
b = InitD3D(Picture1.hWnd)
If Not b Then
MsgBox "Unable to CreateDevice (see InitD3D() source for comments)"
End
End If
' Initialize Vertex Buffer with Geometry
b = InitGeometry()
If Not b Then
MsgBox "Unable to Create VertexBuffer"
End
End If
' Enable Timer to update
Timer1.Enabled = True
End Sub
'-----------------------------------------------------------------------------
' Name: Timer1_Timer()
'-----------------------------------------------------------------------------
Private Sub Timer1_Timer()
Render
End Sub
'-----------------------------------------------------------------------------
' Name: Form_Unload()
'-----------------------------------------------------------------------------
Private Sub Form_Unload(Cancel As Integer)
End
End Sub
'-----------------------------------------------------------------------------
' Name: InitD3D()
' Desc: Initializes Direct3D
'-----------------------------------------------------------------------------
Function InitD3D(hWnd As Long) As Boolean
On Local Error Resume Next
' Create the D3D object
Set g_D3D = g_DX.Direct3DCreate()
If g_D3D Is Nothing Then Exit Function
' Get The current Display Mode format
Dim mode As D3DDISPLAYMODE
g_D3D.GetAdapterDisplayMode D3DADAPTER_DEFAULT, mode
' Set up the structure used to create the D3DDevice. Since we are now
' using more complex geometry, we will create a device with a zbuffer.
' the D3DFMT_D16 indicates we want a 16 bit z buffer but
Dim d3dpp As D3DPRESENT_PARAMETERS
d3dpp.Windowed = 1
d3dpp.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC
d3dpp.BackBufferFormat = mode.Format
d3dpp.BackBufferCount = 1
d3dpp.EnableAutoDepthStencil = 1
d3dpp.AutoDepthStencilFormat = D3DFMT_D16
' Create the D3DDevice
' If you do not have hardware 3d acceleration. Enable the reference rasterizer
' using the DirectX control panel and change D3DDEVTYPE_HAL to D3DDEVTYPE_REF
Set g_D3DDevice = g_D3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, _
D3DCREATE_SOFTWARE_VERTEXPROCESSING, d3dpp)
If g_D3DDevice Is Nothing Then Exit Function
' Device state would normally be set here
' Turn off culling, so we see the front and back of the triangle
g_D3DDevice.SetRenderState D3DRS_CULLMODE, D3DCULL_NONE
' Turn on the zbuffer
g_D3DDevice.SetRenderState D3DRS_ZENABLE, 1
' Note lighting is on by default
InitD3D = True
End Function
'-----------------------------------------------------------------------------
' Name: SetupMatrices()
' Desc: Sets up the world, view, and projection transform matrices.
'-----------------------------------------------------------------------------
Sub SetupMatrices()
' The transform Matrix is used to position and orient the objects
' you are drawing
' For our world matrix, we will just rotate the object about the 1 1 1 axis.
Dim matWorld As D3DMATRIX
D3DXMatrixRotationAxis matWorld, vec3(1, 1, 1), Timer / 4
g_D3DDevice.SetTransform D3DTS_WORLD, matWorld
' The view matrix defines the position and orientation of the camera
' Set up our view matrix. A view matrix can be defined given an eye point,
' a point to lookat, and a direction for which way is up. Here, we set the
' eye five units back along the z-axis and up three units, look at the
' origin, and define "up" to be in the y-direction.
Dim matView As D3DMATRIX
D3DXMatrixLookAtLH matView, vec3(0#, 3#, -5#), _
vec3(0#, 0#, 0#), _
vec3(0#, 1#, 0#)
g_D3DDevice.SetTransform D3DTS_VIEW, matView
' The projection matrix describes the camera's lenses
' For the projection matrix, we set up a perspective transform (which
' transforms geometry from 3D view space to 2D viewport space, with
' a perspective divide making objects smaller in the distance). To build
' a perpsective transform, we need the field of view (1/4 pi is common),
' the aspect ratio, and the near and far clipping planes (which define at
' what distances geometry should be no longer be rendered).
Dim matProj As D3DMATRIX
D3DXMatrixPerspectiveFovLH matProj, g_pi / 4, 1, 1, 1000
g_D3DDevice.SetTransform D3DTS_PROJECTION, matProj
End Sub
'-----------------------------------------------------------------------------
' Name: SetupLights()
' Desc: Sets up the lights and materials for the scene.
'-----------------------------------------------------------------------------
Sub SetupLights()
Dim col As D3DCOLORVALUE
' Set up a material. The material here just has the diffuse and ambient
' colors set to yellow. Note that only one material can be used at a time.
Dim mtrl As D3DMATERIAL8
With col: .r = 1: .g = 1: .b = 0: .a = 1: End With
mtrl.diffuse = col
mtrl.Ambient = col
g_D3DDevice.SetMaterial mtrl
' Set up a white, directional light, with an oscillating direction.
' Note that many lights may be active at a time (but each one slows down
' the rendering of our scene). However, here we are just using one. Also,
' we need to set the D3DRS_LIGHTING renderstate to enable lighting
Dim light As D3DLIGHT8
light.Type = D3DLIGHT_DIRECTIONAL
light.diffuse.r = 1#
light.diffuse.g = 1#
light.diffuse.b = 1#
light.Direction.x = Cos(Timer * 2)
light.Direction.y = 1#
light.Direction.z = Sin(Timer * 2)
light.Range = 1000#
g_D3DDevice.SetLight 0, light 'let d3d know about the light
g_D3DDevice.LightEnable 0, 1 'turn it on
g_D3DDevice.SetRenderState D3DRS_LIGHTING, 1 'make sure lighting is enabled
' Finally, turn on some ambient light.
' Ambient light is light that scatters and lights all objects evenly
g_D3DDevice.SetRenderState D3DRS_AMBIENT, &H202020
End Sub
'-----------------------------------------------------------------------------
' Name: InitGeometry()
' Desc: Creates a vertex buffer and fills it with our vertices.
'-----------------------------------------------------------------------------
Function InitGeometry() As Boolean
Dim i As Long
' Initialize three vertices for rendering a triangle
Dim Vertices(99) As CUSTOMVERTEX
Dim VertexSizeInBytes As Long
Dim theta As Single
VertexSizeInBytes = Len(Vertices(0))
' We are algorithmically generating a cylinder
' here, including the normals, which are used for lighting.
' normals are vectors that are of length 1 and point in a direction
' perpendicular to the plane of the triangle the normal belongs to
' In later tutorials we will use d3dx to generate them
For i = 0 To 49
theta = (2 * g_pi * i) / (50 - 1)
Vertices(2 * i + 0).postion = vec3(Sin(theta), -1, Cos(theta))
Vertices(2 * i + 0).normal = vec3(Sin(theta), 0, Cos(theta))
Vertices(2 * i + 1).postion = vec3(Sin(theta), 1, Cos(theta))
Vertices(2 * i + 1).normal = vec3(Sin(theta), 0, Cos(theta))
Next
' Create the vertex buffer.
Set g_VB = g_D3DDevice.CreateVertexBuffer(VertexSizeInBytes * 50 * 2, _
0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT)
If g_VB Is Nothing Then Exit Function
' fill the vertex buffer from our array
D3DVertexBuffer8SetData g_VB, 0, VertexSizeInBytes * 100, 0, Vertices(0)
InitGeometry = True
End Function
'-----------------------------------------------------------------------------
' Name: Cleanup()
' Desc: Releases all previously initialized objects
'-----------------------------------------------------------------------------
Sub Cleanup()
Set g_VB = Nothing
Set g_D3DDevice = Nothing
Set g_D3D = Nothing
End Sub
'-----------------------------------------------------------------------------
' Name: Render()
' Desc: Draws the scene
'-----------------------------------------------------------------------------
Sub Render()
Dim v As CUSTOMVERTEX
Dim sizeOfVertex As Long
If g_D3DDevice Is Nothing Then Exit Sub
' Clear the backbuffer to a blue color (ARGB = 000000ff)
' Clear the z buffer to 1
g_D3DDevice.Clear 0, ByVal 0, D3DCLEAR_TARGET Or D3DCLEAR_ZBUFFER, &HFF&, 1#, 0
' Begin the scene
g_D3DDevice.BeginScene
' Setup the lights and materials
SetupLights
' Setup the world, view, and projection matrices
SetupMatrices
' Draw the triangles in the vertex buffer
' Note we are now using a triangle strip of vertices
' instead of a triangle list
sizeOfVertex = Len(v)
g_D3DDevice.SetStreamSource 0, g_VB, sizeOfVertex
g_D3DDevice.SetVertexShader D3DFVF_CUSTOMVERTEX
g_D3DDevice.DrawPrimitive D3DPT_TRIANGLESTRIP, 0, (4 * 25) - 2
' End the scene
g_D3DDevice.EndScene
' Present the backbuffer contents to the front buffer (screen)
g_D3DDevice.Present ByVal 0, ByVal 0, 0, ByVal 0
End Sub
'-----------------------------------------------------------------------------
' Name: vec3()
' Desc: helper function
'-----------------------------------------------------------------------------
Function vec3(x As Single, y As Single, z As Single) As D3DVECTOR
vec3.x = x
vec3.y = y
vec3.z = z
End Function

View File

@@ -0,0 +1,34 @@
Type=Exe
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#stdole2.tlb#OLE Automation
Reference=*\G{E1211242-8E94-11D1-8808-00C04FC2C603}#1.0#0#dx8vb.dll#DirectX 8 for Visual Basic Type Library
Form=Tut04_lights.frm
Startup="Form1"
Command32=""
Name="Project1"
ExeName32="vb_Tut04_lights.exe"
HelpContextID="0"
CompatibleMode="0"
MajorVer=1
MinorVer=0
RevisionVer=0
AutoIncrementVer=0
ServerSupportFiles=0
VersionCompanyName="Microsoft"
CompilationType=0
OptimizationType=0
FavorPentiumPro(tm)=0
CodeViewDebugInfo=0
NoAliasing=0
BoundsCheck=0
OverflowCheck=0
FlPointCheck=0
FDIVCheck=0
UnroundedFP=0
StartMode=0
Unattended=0
Retained=0
ThreadPerObject=0
MaxNumberOfThreads=1
[MS Transaction Server]
AutoRefresh=1

View File

@@ -0,0 +1,28 @@
//-----------------------------------------------------------------------------
// Name: Lights Direct3D Tutorial
//
// Copyright (C) 1999-2001 Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
Description
===========
The Lights tutorial shows how to use dynamic lighting in Direct3D.
Path
====
Source: DXSDK\Samples\Multimedia\VBSamples\D3D\Tutorials\Tut04_Lights
Programming Notes
=================
Dynamic lighting makes 3D objects look more realistic. Lights come in a few
flavors, notably point lights and directional lights. Geometry gets lit by
every light in the scene, so adding lights increases rendering time. Point
lights have a poistion and are computationally more expensive than directional
lights, which only have a direction (as if the light source is infinitely far
away). Internal Direct3D lighting calculations require surface normals, so note
that normals are added to the vertices. Also, material properties can be set,
which describe how the surface interacts with the light (i.e. it's color).

View File

@@ -0,0 +1,442 @@
VERSION 5.00
Begin VB.Form Form1
BorderStyle = 1 'Fixed Single
Caption = "Textures"
ClientHeight = 3195
ClientLeft = 45
ClientTop = 330
ClientWidth = 4680
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3195
ScaleWidth = 4680
StartUpPosition = 3 'Windows Default
Begin VB.PictureBox Picture1
Height = 3015
Left = 120
ScaleHeight = 2955
ScaleWidth = 4395
TabIndex = 0
Top = 120
Width = 4455
Begin VB.Timer Timer1
Enabled = 0 'False
Interval = 40
Left = 1920
Top = 1320
End
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'-----------------------------------------------------------------------------
' File: Tut05_textures.frm
'
' Desc: Better than just lights and materials, 3D objects look much more
' convincing when texture-mapped. Textures can be thought of as a sort
' of wallpaper, that is shrinkwrapped to fit a texture. Textures are
' typically loaded from image files, and D3DX provides a utility to
' function to do this for us. Like a vertex buffer, textures have
' Lock() and Unlock() functions to access (read or write) the image
' data. Textures have a width, height, miplevel, and pixel format. The
' miplevel is for "mipmapped" textures, an advanced performance-
' enhancing feature which uses lower resolutions of the texture for
' objects in the distance where detail is less noticeable. The pixel
' format determines how the colors are stored in a texel. The most
' common formats are the 16-bit R5G6B5 format (5 bits of red, 6-bits of
' green and 5 bits of blue) and the 32-bit A8R8G8B8 format (8 bits each
' of alpha, red, green, and blue).
'
' Textures are associated with geometry through texture coordinates.
' Each vertex has one or more sets of texture coordinates, which are
' named tu and tv and range from 0.0 to 1.0. Texture coordinates can be
' supplied by the geometry, or can be automatically generated using
' Direct3D texture coordinate generation (which is an advanced feature).
'
' Copyright (C) 1999-2001 Microsoft Corporation. All rights reserved.
'-----------------------------------------------------------------------------
Option Explicit
'-----------------------------------------------------------------------------
' variables
'-----------------------------------------------------------------------------
Dim g_DX As New DirectX8
Dim g_D3DX As New D3DX8
Dim g_D3D As Direct3D8 ' Used to create the D3DDevice
Dim g_D3DDevice As Direct3DDevice8 ' Our rendering device
Dim g_VB As Direct3DVertexBuffer8 ' Holds our vertex data
Dim g_Texture As Direct3DTexture8 ' Our texture
' A structure for our custom vertex type
Private Type CUSTOMVERTEX
postion As D3DVECTOR '3d position for vertex
color As Long 'color of the vertex
tu As Single 'texture map coordinate
tv As Single 'texture map coordinate
End Type
' Our custom FVF, which describes our custom vertex structure
Const D3DFVF_CUSTOMVERTEX = (D3DFVF_XYZ Or D3DFVF_DIFFUSE Or D3DFVF_TEX1)
Const g_pi = 3.1415
'-----------------------------------------------------------------------------
' Name: Form_Load()
'-----------------------------------------------------------------------------
Private Sub Form_Load()
Dim b As Boolean
' Allow the form to become visible
Me.Show
DoEvents
' Initialize D3D and D3DDevice
b = InitD3D(Picture1.hWnd)
If Not b Then
MsgBox "Unable to CreateDevice (see InitD3D() source for comments)"
End
End If
' Initialize vertex buffer with geometry and load our texture
b = InitGeometry()
If Not b Then
MsgBox "Unable to Create VertexBuffer"
End
End If
' Enable Timer to update
Timer1.Enabled = True
End Sub
'-----------------------------------------------------------------------------
' Name: Timer1_Timer()
'-----------------------------------------------------------------------------
Private Sub Timer1_Timer()
Render
End Sub
'-----------------------------------------------------------------------------
' Name: Form_Unload()
'-----------------------------------------------------------------------------
Private Sub Form_Unload(Cancel As Integer)
Cleanup
End
End Sub
'-----------------------------------------------------------------------------
' Name: InitD3D()
' Desc: Initializes Direct3D
'-----------------------------------------------------------------------------
Function InitD3D(hWnd As Long) As Boolean
On Local Error Resume Next
' Create the D3D object
Set g_D3D = g_DX.Direct3DCreate()
If g_D3D Is Nothing Then Exit Function
' Get The current Display Mode format
Dim mode As D3DDISPLAYMODE
g_D3D.GetAdapterDisplayMode D3DADAPTER_DEFAULT, mode
' Set up the structure used to create the D3DDevice. Since we are now
' using more complex geometry, we will create a device with a zbuffer.
' the D3DFMT_D16 indicates we want a 16 bit z buffer but
Dim d3dpp As D3DPRESENT_PARAMETERS
d3dpp.Windowed = 1
d3dpp.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC
d3dpp.BackBufferFormat = mode.Format
d3dpp.BackBufferCount = 1
d3dpp.EnableAutoDepthStencil = 1
d3dpp.AutoDepthStencilFormat = D3DFMT_D16
' Create the D3DDevice
' If you do not have hardware 3d acceleration. Enable the reference rasterizer
' using the DirectX control panel and change D3DDEVTYPE_HAL to D3DDEVTYPE_REF
Set g_D3DDevice = g_D3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, _
D3DCREATE_SOFTWARE_VERTEXPROCESSING, d3dpp)
If g_D3DDevice Is Nothing Then Exit Function
' Device state would normally be set here
' Turn off culling, so we see the front and back of the triangle
g_D3DDevice.SetRenderState D3DRS_CULLMODE, D3DCULL_NONE
' Turn on the zbuffer
g_D3DDevice.SetRenderState D3DRS_ZENABLE, 1
' Turn off lighting we are going to use colored vertices
g_D3DDevice.SetRenderState D3DRS_LIGHTING, 0
InitD3D = True
End Function
'-----------------------------------------------------------------------------
' Name: SetupMatrices()
' Desc: Sets up the world, view, and projection transform matrices.
'-----------------------------------------------------------------------------
Sub SetupMatrices()
' The transform Matrix is used to position and orient the objects
' you are drawing
' For our world matrix, we will just rotate the object about the 1 1 1 axis.
Dim matWorld As D3DMATRIX
D3DXMatrixRotationAxis matWorld, vec3(1, 1, 1), Timer / 4
g_D3DDevice.SetTransform D3DTS_WORLD, matWorld
' The view matrix defines the position and orientation of the camera
' Set up our view matrix. A view matrix can be defined given an eye point,
' a point to lookat, and a direction for which way is up. Here, we set the
' eye five units back along the z-axis and up three units, look at the
' origin, and define "up" to be in the y-direction.
Dim matView As D3DMATRIX
D3DXMatrixLookAtLH matView, vec3(0#, 3#, -5#), _
vec3(0#, 0#, 0#), _
vec3(0#, 1#, 0#)
g_D3DDevice.SetTransform D3DTS_VIEW, matView
' The projection matrix describes the camera's lenses
' For the projection matrix, we set up a perspective transform (which
' transforms geometry from 3D view space to 2D viewport space, with
' a perspective divide making objects smaller in the distance). To build
' a perpsective transform, we need the field of view (1/4 pi is common),
' the aspect ratio, and the near and far clipping planes (which define at
' what distances geometry should be no longer be rendered).
Dim matProj As D3DMATRIX
D3DXMatrixPerspectiveFovLH matProj, g_pi / 4, 1, 1, 1000
g_D3DDevice.SetTransform D3DTS_PROJECTION, matProj
End Sub
'-----------------------------------------------------------------------------
' Name: SetupLights()
' Desc: Sets up the lights and materials for the scene.
'-----------------------------------------------------------------------------
Sub SetupLights()
Dim col As D3DCOLORVALUE
' Set up a material. The material here just has the diffuse and ambient
' colors set to yellow. Note that only one material can be used at a time.
Dim mtrl As D3DMATERIAL8
With col: .r = 1: .g = 1: .b = 0: .a = 1: End With
mtrl.diffuse = col
mtrl.Ambient = col
g_D3DDevice.SetMaterial mtrl
' Set up a white, directional light, with an oscillating direction.
' Note that many lights may be active at a time (but each one slows down
' the rendering of our scene). However, here we are just using one. Also,
' we need to set the D3DRS_LIGHTING renderstate to enable lighting
Dim light As D3DLIGHT8
light.Type = D3DLIGHT_DIRECTIONAL
light.diffuse.r = 1#
light.diffuse.g = 1#
light.diffuse.b = 1#
light.Direction.x = Cos(Timer * 2)
light.Direction.y = 1#
light.Direction.z = Sin(Timer * 2)
light.Range = 1000#
g_D3DDevice.SetLight 0, light 'let d3d know about the light
g_D3DDevice.LightEnable 0, 1 'turn it on
g_D3DDevice.SetRenderState D3DRS_LIGHTING, 1 'make sure lighting is enabled
' Finally, turn on some ambient light.
' Ambient light is light that scatters and lights all objects evenly
g_D3DDevice.SetRenderState D3DRS_AMBIENT, &H202020
End Sub
'-----------------------------------------------------------------------------
' Name: InitGeometry()
' Desc: Creates a vertex buffer and fills it with our vertices.
'-----------------------------------------------------------------------------
Function InitGeometry() As Boolean
Dim i As Long
'Use D3DX to create a texture from a file based image
Set g_Texture = g_D3DX.CreateTextureFromFile(g_D3DDevice, App.Path + "\banana.bmp")
If g_Texture Is Nothing Then Exit Function
' Initialize three vertices for rendering a triangle
Dim Vertices(99) As CUSTOMVERTEX
Dim VertexSizeInBytes As Long
Dim theta As Single
VertexSizeInBytes = Len(Vertices(0))
' We are algorithmically generating a cylinder
' here, including the normals, which are used for lighting.
' normals are vectors that are of length 1 and point in a direction
' perpendicular to the plane of the triangle the normal belongs to
' In later tutorials we will use d3dx to generate them
For i = 0 To 49
theta = (2 * g_pi * i) / (50 - 1)
Vertices(2 * i + 0).postion = vec3(Sin(theta), -1, Cos(theta))
Vertices(2 * i + 0).color = &HFFFFFFFF 'white
Vertices(2 * i + 0).tu = i / (50 - 1)
Vertices(2 * i + 0).tv = 1
Vertices(2 * i + 1).postion = vec3(Sin(theta), 1, Cos(theta))
Vertices(2 * i + 1).color = &HFF808080 'grey
Vertices(2 * i + 1).tu = i / (50 - 1)
Vertices(2 * i + 1).tv = 0
Next
' Create the vertex buffer.
Set g_VB = g_D3DDevice.CreateVertexBuffer(VertexSizeInBytes * 50 * 2, _
0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT)
If g_VB Is Nothing Then Exit Function
' fill the vertex buffer from our array
D3DVertexBuffer8SetData g_VB, 0, VertexSizeInBytes * 100, 0, Vertices(0)
InitGeometry = True
End Function
'-----------------------------------------------------------------------------
' Name: Cleanup()
' Desc: Releases all previously initialized objects
'-----------------------------------------------------------------------------
Sub Cleanup()
Set g_Texture = Nothing
Set g_VB = Nothing
Set g_D3DDevice = Nothing
Set g_D3D = Nothing
End Sub
'-----------------------------------------------------------------------------
' Name: Render()
' Desc: Draws the scene
'-----------------------------------------------------------------------------
Sub Render()
Dim v As CUSTOMVERTEX
Dim sizeOfVertex As Long
If g_D3DDevice Is Nothing Then Exit Sub
' Clear the backbuffer to a blue color (ARGB = 000000ff)
' Clear the z buffer to 1
g_D3DDevice.Clear 0, ByVal 0, D3DCLEAR_TARGET Or D3DCLEAR_ZBUFFER, &HFF&, 1#, 0
' Begin the scene
g_D3DDevice.BeginScene
' Setup our texture. Using textures introduces the texture stage states,
' which govern how textures get blended together (in the case of multiple
' textures) and lighting information. In this case, we are modulating
' (blending) our texture with the diffuse color of the vertices.
g_D3DDevice.SetTexture 0, g_Texture
g_D3DDevice.SetTextureStageState 0, D3DTSS_COLOROP, D3DTOP_MODULATE
g_D3DDevice.SetTextureStageState 0, D3DTSS_COLORARG1, D3DTA_TEXTURE
g_D3DDevice.SetTextureStageState 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE
g_D3DDevice.SetTextureStageState 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE
'Uncomment to learn about texture coordinate matrices
'AnimateTextureCoordinates
' Setup the world, view, and projection matrices
SetupMatrices
' Draw the triangles in the vertex buffer
' Note we are now using a triangle strip of vertices
' instead of a triangle list
sizeOfVertex = Len(v)
g_D3DDevice.SetStreamSource 0, g_VB, sizeOfVertex
g_D3DDevice.SetVertexShader D3DFVF_CUSTOMVERTEX
g_D3DDevice.DrawPrimitive D3DPT_TRIANGLESTRIP, 0, (4 * 25) - 2
' End the scene
g_D3DDevice.EndScene
' Present the backbuffer contents to the front buffer (screen)
g_D3DDevice.Present ByVal 0, ByVal 0, 0, ByVal 0
End Sub
'-----------------------------------------------------------------------------
' Name: AnimateTextureCoordinates()
' Desc: Advanced technique for generating texture coordinates
'-----------------------------------------------------------------------------
Sub AnimateTextureCoordinates()
' Note: to use D3D texture coordinate generation, use the stage state
' D3DTSS_TEXCOORDINDEX, as shown below. In this example, we are using
' the position of the vertex in camera space to generate texture
' coordinates. The tex coord index (TCI) parameters are passed into a
' texture transform, which is a 4x4 matrix which transforms the x,y,z
' TCI coordinates into tu, tv texture coordinates.
' In this example, the texture matrix is setup to
' transform the texture from (-1,+1) position coordinates to (0,1)
' texture coordinate space:
' tu = 0.25*x + 0.5
' tv = -0.25*y + 0.5
Dim mat As D3DMATRIX
mat.m11 = 0.25: mat.m12 = 0#: mat.m13 = 0#: mat.m14 = 0#
mat.m21 = 0#: mat.m22 = -0.25: mat.m23 = 0#: mat.m24 = 0#
mat.m31 = 0#: mat.m32 = 0#: mat.m33 = 1#: mat.m34 = 0#
mat.m41 = 0.5: mat.m42 = 0.5: mat.m43 = 0#: mat.m44 = 1#
g_D3DDevice.SetTransform D3DTS_TEXTURE0, mat
g_D3DDevice.SetTextureStageState 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2
g_D3DDevice.SetTextureStageState 0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION
End Sub
'-----------------------------------------------------------------------------
' Name: vec3()
' Desc: helper function
'-----------------------------------------------------------------------------
Function vec3(x As Single, y As Single, z As Single) As D3DVECTOR
vec3.x = x
vec3.y = y
vec3.z = z
End Function

View File

@@ -0,0 +1,34 @@
Type=Exe
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#stdole2.tlb#OLE Automation
Reference=*\G{E1211242-8E94-11D1-8808-00C04FC2C603}#1.0#0#dx8vb.dll#DirectX 8 for Visual Basic Type Library
Form=Tut05_textures.frm
Startup="Form1"
Command32=""
Name="Project1"
ExeName32="vb_Tut05_Textures.exe"
HelpContextID="0"
CompatibleMode="0"
MajorVer=1
MinorVer=0
RevisionVer=0
AutoIncrementVer=0
ServerSupportFiles=0
VersionCompanyName="Microsoft"
CompilationType=0
OptimizationType=0
FavorPentiumPro(tm)=0
CodeViewDebugInfo=0
NoAliasing=0
BoundsCheck=0
OverflowCheck=0
FlPointCheck=0
FDIVCheck=0
UnroundedFP=0
StartMode=0
Unattended=0
Retained=0
ThreadPerObject=0
MaxNumberOfThreads=1
[MS Transaction Server]
AutoRefresh=1

Binary file not shown.

After

Width:  |  Height:  |  Size: 192 KiB

View File

@@ -0,0 +1,28 @@
//-----------------------------------------------------------------------------
// Name: Textures Direct3D Tutorial
//
// Copyright (C) 1999-2001 Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
Description
===========
The Textures tutorial shows how to use texture mapping in Direct3D.
Path
====
Source: DXSDK\Samples\Multimedia\VBSamples\D3D\Tutorials\Tut05_Textures
Programming Notes
=================
Texture-mapping is like shrink-wrapping a wall paper to a 3D object. A classic
example is applying an image of wood to an otherwise plain cube, to give the
appearance as if the block is actually made of wood. Textures (in their
simplest form) are 2D images, usually loaded from an image file. This tutorial
shows how to use D3DX to create a texture from a file-based image and apply it
to a geometry. Textures require the vertices to have texture coordinates, and
make use of certain RenderStates and TextureStageStates and show in the source
code.

View File

@@ -0,0 +1,384 @@
VERSION 5.00
Begin VB.Form Form1
BorderStyle = 1 'Fixed Single
Caption = "Meshes"
ClientHeight = 3195
ClientLeft = 45
ClientTop = 330
ClientWidth = 4680
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3195
ScaleWidth = 4680
StartUpPosition = 3 'Windows Default
Begin VB.PictureBox Picture1
Height = 3015
Left = 120
ScaleHeight = 2955
ScaleWidth = 4395
TabIndex = 0
Top = 120
Width = 4455
Begin VB.Timer Timer1
Enabled = 0 'False
Interval = 40
Left = 1920
Top = 1320
End
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'-----------------------------------------------------------------------------
' File: Tut06_meshes.frm
'
'
' Desc: For advanced geometry, most apps will prefer to load pre-authored
' meshes from a file. Fortunately, when using meshes, D3DX does most of
' the work for this, parsing a geometry file and creating vertx buffers
' (and index buffers) for us. This tutorial shows how to use a D3DXMESH
' object, including loading it from a file and rendering it. One thing
' D3DX does not handle for us is the materials and textures for a mesh,
' so note that we have to handle those manually.
'
' Note: one advanced (but nice) feature that we don't show here, is that
' when cloning a mesh we can specify the FVF. So, regardless of how the
' mesh was authored, we can add/remove normals, add more texture
' coordinate sets (for multi-texturing), etc..
'
'
' Copyright (C) 1999-2001 Microsoft Corporation. All rights reserved.
'-----------------------------------------------------------------------------
Option Explicit
'-----------------------------------------------------------------------------
' variables
'-----------------------------------------------------------------------------
Dim g_DX As New DirectX8
Dim g_D3DX As New D3DX8
Dim g_D3D As Direct3D8 ' Used to create the D3DDevice
Dim g_D3DDevice As Direct3DDevice8 ' Our rendering device
Dim g_Mesh As D3DXMesh ' Our Mesh
Dim g_MeshMaterials() As D3DMATERIAL8 ' Mesh Material data
Dim g_MeshTextures() As Direct3DTexture8 ' Mesh Textures
Dim g_NumMaterials As Long
Const g_pi = 3.1415
'-----------------------------------------------------------------------------
' Name: Form_Load()
'-----------------------------------------------------------------------------
Private Sub Form_Load()
Dim b As Boolean
' Allow the form to become visible
Me.Show
DoEvents
' Initialize D3D and D3DDevice
b = InitD3D(Picture1.hWnd)
If Not b Then
MsgBox "Unable to CreateDevice (see InitD3D() source for comments)"
End
End If
' Initialize vertex buffer with geometry and load our texture
b = InitGeometry()
If Not b Then
MsgBox "Unable to Create VertexBuffer"
End
End If
' Enable Timer to update
Timer1.Enabled = True
End Sub
'-----------------------------------------------------------------------------
' Name: Timer1_Timer()
'-----------------------------------------------------------------------------
Private Sub Timer1_Timer()
Render
End Sub
'-----------------------------------------------------------------------------
' Name: Form_Unload()
'-----------------------------------------------------------------------------
Private Sub Form_Unload(Cancel As Integer)
Cleanup
End
End Sub
'-----------------------------------------------------------------------------
' Name: InitD3D()
' Desc: Initializes Direct3D
'-----------------------------------------------------------------------------
Function InitD3D(hWnd As Long) As Boolean
On Local Error Resume Next
' Create the D3D object
Set g_D3D = g_DX.Direct3DCreate()
If g_D3D Is Nothing Then Exit Function
' Get The current Display Mode format
Dim mode As D3DDISPLAYMODE
g_D3D.GetAdapterDisplayMode D3DADAPTER_DEFAULT, mode
' Set up the structure used to create the D3DDevice. Since we are now
' using more complex geometry, we will create a device with a zbuffer.
' the D3DFMT_D16 indicates we want a 16 bit z buffer but
Dim d3dpp As D3DPRESENT_PARAMETERS
d3dpp.Windowed = 1
d3dpp.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC
d3dpp.BackBufferFormat = mode.Format
d3dpp.BackBufferCount = 1
d3dpp.EnableAutoDepthStencil = 1
d3dpp.AutoDepthStencilFormat = D3DFMT_D16
' Create the D3DDevice
' If you do not have hardware 3d acceleration. Enable the reference rasterizer
' using the DirectX control panel and change D3DDEVTYPE_HAL to D3DDEVTYPE_REF
Set g_D3DDevice = g_D3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, _
D3DCREATE_SOFTWARE_VERTEXPROCESSING, d3dpp)
If g_D3DDevice Is Nothing Then Exit Function
' Device state would normally be set here
' Turn off culling, so we see the front and back of the triangle
'g_D3DDevice.SetRenderState D3DRS_CULLMODE, D3DCULL_NONE
' Turn on the zbuffer
g_D3DDevice.SetRenderState D3DRS_ZENABLE, 1
' Turn on lighting
g_D3DDevice.SetRenderState D3DRS_LIGHTING, 0
' Turn on full ambient light to white
g_D3DDevice.SetRenderState D3DRS_AMBIENT, &HFFFFFFFF
InitD3D = True
End Function
'-----------------------------------------------------------------------------
' Name: SetupMatrices()
' Desc: Sets up the world, view, and projection transform matrices.
'-----------------------------------------------------------------------------
Sub SetupMatrices()
' The transform Matrix is used to position and orient the objects
' you are drawing
' For our world matrix, we will just rotate the object about the y axis.
Dim matWorld As D3DMATRIX
D3DXMatrixRotationAxis matWorld, vec3(0, 1, 0), Timer / 4
g_D3DDevice.SetTransform D3DTS_WORLD, matWorld
' The view matrix defines the position and orientation of the camera
' Set up our view matrix. A view matrix can be defined given an eye point,
' a point to lookat, and a direction for which way is up. Here, we set the
' eye five units back along the z-axis and up three units, look at the
' origin, and define "up" to be in the y-direction.
Dim matView As D3DMATRIX
D3DXMatrixLookAtLH matView, vec3(0#, 3#, -5#), _
vec3(0#, 0#, 0#), _
vec3(0#, 1#, 0#)
g_D3DDevice.SetTransform D3DTS_VIEW, matView
' The projection matrix describes the camera's lenses
' For the projection matrix, we set up a perspective transform (which
' transforms geometry from 3D view space to 2D viewport space, with
' a perspective divide making objects smaller in the distance). To build
' a perpsective transform, we need the field of view (1/4 pi is common),
' the aspect ratio, and the near and far clipping planes (which define at
' what distances geometry should be no longer be rendered).
Dim matProj As D3DMATRIX
D3DXMatrixPerspectiveFovLH matProj, g_pi / 4, 1, 1, 1000
g_D3DDevice.SetTransform D3DTS_PROJECTION, matProj
End Sub
'-----------------------------------------------------------------------------
' Name: SetupLights()
' Desc: Sets up the lights and materials for the scene.
'-----------------------------------------------------------------------------
Sub SetupLights()
Dim col As D3DCOLORVALUE
' Set up a material. The material here just has the diffuse and ambient
' colors set to yellow. Note that only one material can be used at a time.
Dim mtrl As D3DMATERIAL8
With col: .r = 1: .g = 1: .b = 0: .a = 1: End With
mtrl.diffuse = col
mtrl.Ambient = col
g_D3DDevice.SetMaterial mtrl
' Set up a white, directional light, with an oscillating direction.
' Note that many lights may be active at a time (but each one slows down
' the rendering of our scene). However, here we are just using one. Also,
' we need to set the D3DRS_LIGHTING renderstate to enable lighting
Dim light As D3DLIGHT8
light.Type = D3DLIGHT_DIRECTIONAL
light.diffuse.r = 1#
light.diffuse.g = 1#
light.diffuse.b = 1#
light.Direction.x = Cos(Timer * 2)
light.Direction.y = 1#
light.Direction.z = Sin(Timer * 2)
light.Range = 1000#
g_D3DDevice.SetLight 0, light 'let d3d know about the light
g_D3DDevice.LightEnable 0, 1 'turn it on
g_D3DDevice.SetRenderState D3DRS_LIGHTING, 1 'make sure lighting is enabled
' Finally, turn on some ambient light.
' Ambient light is light that scatters and lights all objects evenly
g_D3DDevice.SetRenderState D3DRS_AMBIENT, &H202020
End Sub
'-----------------------------------------------------------------------------
' Name: InitGeometry()
' Desc: Load Mesh and textures
'-----------------------------------------------------------------------------
Function InitGeometry() As Boolean
Dim MtrlBuffer As D3DXBuffer 'a d3dxbuffer is a generic chunk of memory
Dim i As Long
' Load the mesh from the specified file
' filename = x file to load
' flags = D3DXMESH_MANAGED allow d3dx manage the memory usage of this geometry
' device = g_d3ddevice (if we destroy the device we have to reload the geomerty)
' adjacenyBuffer = nothing (we dont need it)
' materialBuffer = MtrlBuffer (this variable will be filled in with a new object)
Set g_Mesh = g_D3DX.LoadMeshFromX(App.Path + "\Tiger.x", D3DXMESH_MANAGED, _
g_D3DDevice, Nothing, MtrlBuffer, g_NumMaterials)
If g_Mesh Is Nothing Then Exit Function
'allocate space for our materials and textures
ReDim g_MeshMaterials(g_NumMaterials - 1)
ReDim g_MeshTextures(g_NumMaterials - 1)
Dim strTexName As String
' We need to extract the material properties and texture names
' from the MtrlBuffer
For i = 0 To g_NumMaterials - 1
' Copy the material using the d3dx helper function
g_D3DX.BufferGetMaterial MtrlBuffer, i, g_MeshMaterials(i)
' Set the ambient color for the material (D3DX does not do this)
g_MeshMaterials(i).Ambient = g_MeshMaterials(i).diffuse
' Create the texture
strTexName = g_D3DX.BufferGetTextureName(MtrlBuffer, i)
If strTexName <> "" Then
Set g_MeshTextures(i) = g_D3DX.CreateTextureFromFile(g_D3DDevice, App.Path + "\" + strTexName)
End If
Next
Set MtrlBuffer = Nothing
InitGeometry = True
End Function
'-----------------------------------------------------------------------------
' Name: Cleanup()
' Desc: Releases all previously initialized objects
'-----------------------------------------------------------------------------
Sub Cleanup()
Erase g_MeshTextures
Erase g_MeshMaterials
Set g_Mesh = Nothing
Set g_D3DDevice = Nothing
Set g_D3D = Nothing
End Sub
'-----------------------------------------------------------------------------
' Name: Render()
' Desc: Draws the scene
'-----------------------------------------------------------------------------
Sub Render()
Dim i As Long
If g_D3DDevice Is Nothing Then Exit Sub
' Clear the backbuffer to a blue color (ARGB = 000000ff)
' Clear the z buffer to 1
g_D3DDevice.Clear 0, ByVal 0, D3DCLEAR_TARGET Or D3DCLEAR_ZBUFFER, &HFF&, 1#, 0
' Setup the world, view, and projection matrices
SetupMatrices
' Begin the scene
g_D3DDevice.BeginScene
' Meshes are divided into subsets, one for each material.
' Render them in a loop
For i = 0 To g_NumMaterials - 1
' Set the material and texture for this subset
g_D3DDevice.SetMaterial g_MeshMaterials(i)
g_D3DDevice.SetTexture 0, g_MeshTextures(i)
' Draw the mesh subset
g_Mesh.DrawSubset i
Next
' End the scene
g_D3DDevice.EndScene
' Present the backbuffer contents to the front buffer (screen)
g_D3DDevice.Present ByVal 0, ByVal 0, 0, ByVal 0
End Sub
'-----------------------------------------------------------------------------
' Name: vec3()
' Desc: helper function
'-----------------------------------------------------------------------------
Function vec3(x As Single, y As Single, z As Single) As D3DVECTOR
vec3.x = x
vec3.y = y
vec3.z = z
End Function

View File

@@ -0,0 +1,34 @@
Type=Exe
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#stdole2.tlb#OLE Automation
Reference=*\G{E1211242-8E94-11D1-8808-00C04FC2C603}#1.0#0#dx8vb.dll#DirectX 8 for Visual Basic Type Library
Form=Tut06_meshes.frm
Startup="Form1"
Command32=""
Name="Project1"
ExeName32="vb_Tut06_Meshes.exe"
HelpContextID="0"
CompatibleMode="0"
MajorVer=1
MinorVer=0
RevisionVer=0
AutoIncrementVer=0
ServerSupportFiles=0
VersionCompanyName="Microsoft"
CompilationType=0
OptimizationType=0
FavorPentiumPro(tm)=0
CodeViewDebugInfo=0
NoAliasing=0
BoundsCheck=0
OverflowCheck=0
FlPointCheck=0
FDIVCheck=0
UnroundedFP=0
StartMode=0
Unattended=0
Retained=0
ThreadPerObject=0
MaxNumberOfThreads=1
[MS Transaction Server]
AutoRefresh=1

View File

@@ -0,0 +1,26 @@
//-----------------------------------------------------------------------------
// Name: Meshes Direct3D Tutorial
//
// Copyright (C) 1999-2001 Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
Description
===========
The Textures tutorial shows how to load and render file-based geometry
meshes in Direct3D.
Path
====
Source: DXSDK\Samples\Multimedia\VBSamples\D3D\Tutorials\Tut06_Meshes
Programming Notes
=================
Complicated geometry is usally modelled using 3D modelling software and
saved in a file, such as Microsoft's .x file format. Using meshes can be
somewhat involved, but fortunately D3DX contains functions to help out. This
tutorial shows how use the D3DX functions to load and render file-based
meshes. Note that we still have to handle materials and textures manually.

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

File diff suppressed because it is too large Load Diff