Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

The following code is a complete XNA 3.1 program almost unaltered to that code skeleton Visual Studio is creating when creating a new project.

The only things I have changed are

  • imported a .x model to the content folder of the VS solution.

    (the model is a simple square with a texture spanning over it - made in Google Sketchup and exported with several .x exporters)

  • in the Load() method I am loading the .x model into the game.

  • The Draw() method uses a BasicEffect to render the model.

Except these three things I haven't added any code.

Why does the model does not show the texture ? What can I do to make the texture visible ?

This is the texture file (a standard SketchUp texture from the palette):

enter image description here

And this is what my program looks like - as you can see: No texture!

enter image description here

Find below the complete source code of the program AND the complete .x file:

namespace WindowsGame1 {
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game {
    GraphicsDeviceManager graphics;
    SpriteBatch spriteBatch;

    public Game1() {
        graphics = new GraphicsDeviceManager(this);
        Content.RootDirectory = "Content";
    }

    /// <summary>
    /// Allows the game to perform any initialization it needs to before starting to run.
    /// This is where it can query for any required services and load any non-graphic
    /// related content.  Calling base.Initialize will enumerate through any components
    /// and initialize them as well.
    /// </summary>
    protected override void Initialize() {
        // TODO: Add your initialization logic here
        base.Initialize();
    }

    Model newModel;

    /// <summary>
    /// LoadContent will be called once per game and is the place to load
    /// all of your content.
    /// </summary>
    protected override void LoadContent() {
        // Create a new SpriteBatch, which can be used to draw textures.
        spriteBatch = new SpriteBatch(GraphicsDevice);

        // TODO: usse this.Content to load your game content here

        newModel = Content.Load<Model>(@"aau3d");

        foreach (ModelMesh mesh in newModel.Meshes) {

            foreach (ModelMeshPart meshPart in mesh.MeshParts) {

                meshPart.Effect = new BasicEffect(this.GraphicsDevice, null);
            }
        }

    }

    /// <summary>
    /// UnloadContent will be called once per game and is the place to unload
    /// all content.
    /// </summary>
    protected override void UnloadContent() {
        // TODO: Unload any non ContentManager content here
    }

    /// <summary>
    /// Allows the game to run logic such as updating the world,
    /// checking for collisions, gathering input, and playing audio.
    /// </summary>
    /// <param name="gameTime">Provides a snapshot of timing values.</param>
    protected override void Update(GameTime gameTime) {
        // Allows the game to exit
        if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            this.Exit();

        // TODO: Add your update logic here

        base.Update(gameTime);
    }

    /// <summary>
    /// This is called when the game should draw itself.
    /// </summary>
    /// <param name="gameTime">Provides a snapshot of timing values.</param>
    protected override void Draw(GameTime gameTime) {

        if (newModel != null) {

            GraphicsDevice.Clear(Color.CornflowerBlue);

            Matrix[] transforms = new Matrix[newModel.Bones.Count];
            newModel.CopyAbsoluteBoneTransformsTo(transforms);

            foreach (ModelMesh mesh in newModel.Meshes) {
                foreach (BasicEffect effect in mesh.Effects) {
                    effect.EnableDefaultLighting();
                    effect.TextureEnabled = true;

                    effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateRotationY(0)
                * Matrix.CreateTranslation(new Vector3(0, 0, 0));
                    effect.View = Matrix.CreateLookAt(new Vector3(200, 1000, 200), Vector3.Zero, Vector3.Up);
                    effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f),
                        0.75f, 1.0f, 10000.0f);
                }
                mesh.Draw();
            }
        }

        base.Draw(gameTime);
    }
}

}

This is the model I am using (.x):

xof 0303txt 0032 
// SketchUp 6 -> DirectX (c)2008 edecadoudal, supports: faces, normals and textures 

Material Default_Material{

1.0;1.0;1.0;1.0;;
3.2;
0.000000;0.000000;0.000000;;
0.000000;0.000000;0.000000;;
} 
Material _Groundcover_RiverRock_4inch_{ 
0.568627450980392;0.494117647058824;0.427450980392157;1.0;;
3.2;
0.000000;0.000000;0.000000;;
0.000000;0.000000;0.000000;;
   TextureFilename { "aau3d.xGroundcover_RiverRock_4inch.jpg";   } 
} 
Mesh mesh_0{
 4;
 -81.6535;0.0000;74.8031;,
 -0.0000;0.0000;0.0000;,
 -81.6535;0.0000;0.0000;,
 -0.0000;0.0000;74.8031;;
 2;
 3;0,1,2,
 3;1,0,3;;
  MeshMaterialList {
  2;
  2;
  1,
  1;
  { Default_Material }
  { _Groundcover_RiverRock_4inch_ }
  }
  MeshTextureCoords {
  4;
  -2.1168,-3.4022;
  1.0000,-0.0000;
  1.0000,-3.4022;
  -2.1168,-0.0000;;
  }
  MeshNormals {
  4;
    0.0000;1.0000;-0.0000;
0.0000;1.0000;-0.0000;
0.0000;1.0000;-0.0000;
0.0000;1.0000;-0.0000;;
  2;
  3;0,1,2;
  3;1,0,3;;
  }
 }
share|improve this question
    
It's different in that way that I have broken down my program to its minimum and that the resulting error has changed: instead of an deformed texture I now have no texture at all. –  marc wellman Oct 11 '12 at 23:38
    
Because the problem described there still exists. This question here would help me to draw a model in its pure form which I can then use as a pattern in order to try to solve the other problem. –  marc wellman Oct 11 '12 at 23:44
    
Can you post what the texture coordinates look like in the exported file? –  Byte56 Oct 12 '12 at 0:44
    
@Byte56 of course, .. I've added the file at the end of my post ... –  marc wellman Oct 12 '12 at 0:51
    
Bummer. I was hoping they would be weird, they look normal. Have you looked at this? You're also sure the texture is available to the game? In whatever resources directory is specified? –  Byte56 Oct 12 '12 at 0:53

1 Answer 1

Fortunately this question has been answered by another user at SO.

If your interested in the end of the story please refer to here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.