I am trying to apply a texture to a mesh that has no texture. All that's happening is that only a single color from the texture file is being applied to the mesh, but the entire texture is not displaying. Here's the rendering code:

Dim mat As Material = New Material

mat.Ambient = Color.White

mat.Diffuse = Color.White

device.SetTexture(0, Nothing)

device.SetTexture(0, texture)

device.Material = mat

Dim matFirst As Matrix = Matrix.Multiply(Matrix.RotationYawPitchRoll(25, 20, 0), Matrix.Scaling(New Vector3(0.6F, 1.0F, 1.0F)))

device.Transform.World = Matrix.Multiply(matFirst, Matrix.Translation(Vec3(iii)))


Here's the code I use to load the mesh and texture.

texture = TextureLoader.FromFile(device, "texture.bmp")

For iii = 0 To index

Me.meshes(iii) = mesh.FromFile("mesh.x", MeshFlags.SystemMemory, device, mats)


Next iii

I would like to get it to apply the entire texture, not just a single color. What am I doing wrong I am using the October 2006 version of DirectX, and Visual Basic .NET 2003 Standard.

Re: Game Technologies: DirectX 101 Applying Texture to Mesh

The ZMan

You can only apply a texture if the mesh has texture coordinates. If it doesn't then you need to clone the mesh and add some coordinates. This is not something that is obvious as usually its done by the artist that makes the mesh. Check out the tutorials in the DirectX SDK. They show adding the banana texture to a cylinder.

Re: Game Technologies: DirectX 101 Applying Texture to Mesh


Thank you for the response! It's working so far!