Reputation: 127
I'm trying to make a 3D game for the first time in XNA, I already have experience with 2D and C# coding, but this is throwing me off a little.
I'm trying to draw a texture on a 3D object (an unfinished gun model that I'm working on in Blender) the model loads, but is completely white (intended), now I want to draw a gray color onto the gun using this:
private void DrawModel(Model model, Matrix world, Matrix view, Matrix projection)
{
foreach (ModelMesh mesh in model.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.EnableDefaultLighting();
effect.TextureEnabled = true;
effect.Texture = guntexture;
effect.World = world;
effect.View = view;
effect.Projection = projection;
}
mesh.Draw();
}
}
guntexture is a Texture2D that I loaded the normal way, which is basically a gray square made in Paint.
The issue is that now when I compile, I get this error: "The current vertex declaration does not include all the elements required by the current vertex shader. TextureCoordinate0 is missing."
More importantly, I feel the error is being generated by these two:
effect.TextureEnabled = true;
effect.Texture = guntexture;
removing the first one results in the game compiling, but without the texture. Keeping it and setting it to false does the same. I also tried reordering it, but that didn't work, same thing.
Please help me understand whats going on, is there something wrong with the texture? or the gun?
In addition, I am able to light the gun using the default lighting without errors.
Upvotes: 1
Views: 1469
Reputation: 4411
You are missing texture uv coordinates. You have to export them with the mesh. If they don't exist you can create them in blender.
If you don't have uv coordinates check this blender texture tutorial.
This tutorial shows how to use a basic effect with texturing in xna
Upvotes: 2