This project is read-only.

Texture2D problem

Nov 4, 2009 at 3:20 AM

Hi all,

I'm trying to add a texture to a cube y my program for this I use the following code,

            GeometryNode groundNode = new GeometryNode("Ground");

            groundNode.Model = new Box(1);

            Material groundMaterial = new Material();
            groundMaterial.Diffuse = Color.White.ToVector4();
            groundMaterial.Specular = Color.White.ToVector4();
            groundMaterial.SpecularPower = 20;
            groundMaterial.Texture = Content.Load<Texture2D>("pc_tiedown");

            groundNode.Material = groundMaterial;

            TransformNode groundTransform = new TransformNode();
            groundTransform.Rotation = Quaternion.Identity;
            groundTransform.Translation = new Vector3(0,0,0);
            groundTransform.Scale = new Vector3(1, 1, 1);


the problem is that I don't get what I've expected, I mean, I can't see the texture in the box, I get a plain grey box. The texture I use in fact is gray but has disigns in it an these aren't shown in my box.

For these I wanted to ask wheather the files used as textures must have a especific file format? I'm using a 512x512, png format image.

Thank you for u're time.

Felipe del Río

Nov 4, 2009 at 5:19 PM

Hi Felipe,

As mentioned somewhere in the user manual, we do not support texture mapping automatically for the primitive shapes we provide (Box, Sphere, Cone, etc), because we have no idea how exactly you want to texture map it. You need to specify the texture coordinates for each of the vertices if you want to texture map anything to a geometry. 

Please see Tutorial 7 to see how you can create your own shape with specific texture. For a box geometry, you can see how I created it in the Goblin source.