Putting textures on walls

ochensati
06-03-2002, 03:23 PM
I am trying to put a texture on a simple square surface and am failing miserably. Here is my code


Set groundTexture = CreateTextureSurface(App.Path + "\texture.bmp" _
, 256, 256)
square.AddVertex 0, WidthoP / 2, 0, HeightoP / 2, 0, 0, 1, 0, 0
square.AddVertex 0, WidthoP / 2 + 10, 0, HeightoP / 2, 0, 0, 1, 1, 0
square.AddVertex 0, WidthoP / 2 + 10, 10, HeightoP / 2, 0, 0, 1, 1, 1
square.AddVertex 0, WidthoP / 2, 10, HeightoP / 2, 0, 0, 1, 0, 1
square.AddIndices 0, 0, 2, 1
square.AddIndices 0, 0, 3, 2

Device.BeginScene
Device.SetTexture 0, groundTexture

Call square.render(0)
device.endscene




and here are the procedures to go with that


Public Sub render(index As Long, Optional mode As Integer = 0)
Call Device.DrawIndexedPrimitive(D3DPT_TRIANGLELIST, _
D3DFVF_VERTEX, ObjMdl(index).Vertices(0), _
UBound(ObjMdl(index).Vertices) + 1, ObjMdl(index).Indices, _
UBound(ObjMdl(index).Indices) + 1, D3DDP_DEFAULT)

End Sub


Public Function AddVertex(ModelNum As Integer, X As Single, Y As Single, z As Single, nx As Single, ny As Single, nz As Single, tx As Single, ty As Single)

With ObjMdl(ModelNum)
ReDim Preserve .Vertices(.Numverts)
Call dx.CreateD3DVertex(X, Y, z, nx, ny, nz, tx, ty, .Vertices(.Numverts))
.Numverts = .Numverts + 1

End With
End Function



and the last part I got off of Jack Hoxley's site but had to modify a little as it did not accept 32 bit textures so



Public Function CreateTextureSurface(sFile As String, Optional pWidth As Long = 0, Optional pHeight As Long = 0, _
Optional ColKey As Integer = 0) As DirectDrawSurface7


Dim bOK As Boolean
Dim enumTex As Direct3DEnumPixelFormats
Dim sLoadFile As String
Dim i As Long
Dim ddsd As DDSURFACEDESC2
Dim SurfaceObject As DirectDrawSurface7
Dim Init As Boolean

'Set our flags to tell the surface its a texture
back.GetSurfaceDesc ddsd

ddsd.lFlags = DDSD_CAPS Or DDSD_TEXTURESTAGE Or DDSD_PIXELFORMAT

'If width and height were specified then make our texture that size,
'otherwise it will be its normal size
If ((pHeight <> 0) And (pWidth <> 0)) Then
ddsd.lFlags = ddsd.lFlags Or DDSD_HEIGHT Or DDSD_WIDTH
ddsd.lHeight = pHeight
ddsd.lWidth = pWidth
End If

Set enumTex = Device.GetTextureFormatsEnum()

'check if device supports 16bit surfaces
Dim min As Integer, minI As Integer
For i = 1 To enumTex.GetCount()
bOK = True
Call enumTex.GetItem(i, ddsd.ddpfPixelFormat) '

With ddsd.ddpfPixelFormat
If .lRGBBitCount >= min And .lRGBBitCount >= 16 Then
min = .lRGBBitCount
minI = i
bOK = False
End If
End With

If bOK = True Then Exit For
Next

Call enumTex.GetItem(minI, ddsd.ddpfPixelFormat)

If bOK = False Then
Debug.Print "Unable to find 16bit surface support on your hardware - exiting"
Init = False
End If

'set some texture surface flags
If Device.GetDeviceGuid() = "IID_IDirect3DHALDevice" Then
ddsd.ddsCaps.lCaps = DDSCAPS_TEXTURE
ddsd.ddsCaps.lCaps2 = DDSCAPS2_TEXTUREMANAGE
ddsd.lTextureStage = 0
Else
ddsd.ddsCaps.lCaps = DDSCAPS_TEXTURE
ddsd.ddsCaps.lCaps2 = 0
ddsd.lTextureStage = 0
End If

'If no filename was passed then create a blank surface
If sFile = "" Then
Set SurfaceObject = DD.CreateSurface(ddsd)
Else
Set SurfaceObject = DD.CreateSurfaceFromFile(sFile, ddsd)
End If

Set CreateTextureSurface = SurfaceObject

'Colour key
Dim ddckColourKey As DDCOLORKEY
Dim ddpf As DDPIXELFORMAT

'Make a Black colorkey
If ColKey = 1 Then
ddckColourKey.low = 0
ddckColourKey.high = 0
CreateTextureSurface.SetColorKey DDCKEY_SRCBLT, ddckColourKey

'Make a Magneta Colorkey, rgb(255,0,255)
ElseIf ColKey = 2 Then
CreateTextureSurface.GetPixelFormat ddpf
ddckColourKey.low = ddpf.lBBitMask + ddpf.lRBitMask
ddckColourKey.high = ddckColourKey.low
CreateTextureSurface.SetColorKey DDCKEY_SRCBLT, ddckColourKey
End If
End Function



I would think that everything would come out fine, but I keep getting and image that looks like scrambled eggs. Does anyone know what is wrong or know the location of a better textures tutorial?

http://http://www.public.asu.edu/~bashc/temp.bmp

ochensati
06-03-2002, 04:19 PM
I am begining to feel like the church lady. Nevermind! I got a different texture loading procedure from lucky's vb gaming site and now everything works great.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum