SnOrfus

I'm sure there's something simple that I'm missing but I'm just trying to texture a sphere here. If I comment out the:
e.Texture = texture;
e.TextureEnabled = true;
I get a nicely lit green sphere, but otherwise it's just a black circle.

The model was made in blender and exported to an xfile. I've tried it both with the normals flipped/not flipped and with the texture applied in blender and not (wasn't sure if it'd make a difference) as well as both left and right handed system.

// Load the model/texture
public override void Initialize(GraphicsDeviceManager g)
{
ball = c.Load<Model>(@"Content\Models\ball");
texture = c.Load<Texture2D>(@"Content\Models\tmppolar");
}

//...

public override void Render(GraphicsDeviceManager graphics)
{
Matrix[] transforms;
GraphicsDevice g = graphics.GraphicsDevice;

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

foreach (ModelMesh mesh in ball.Meshes)
{
foreach (BasicEffect e in mesh.Effects)
{
// Lighting
e.LightingEnabled = true;
e.DirectionalLight0.Enabled = true;
e.DirectionalLight0.Direction = new Vector3(0.0f, -1.0f, 0.0f);
e.DirectionalLight0.DiffuseColor = new Vector3(1.0f, 1.0f, 1.0f);

// Material
e.SpecularPower = 10.0f;
e.AmbientLightColor = new Vector3(1.0f, 1.0f, 1.0f);
e.DiffuseColor = new Vector3(0.4f, 0.5f, 0.3f);

// Texturing
e.Texture = texture;
e.TextureEnabled = true;

// Matricies/Transforms
e.World = transforms[mesh.ParentBone.Index];
e.View = Program.camera.View;
e.Projection = Program.camera.Projection;
}

mesh.Draw();
}

transformation = Matrix.CreateRotationX(modelXRotation); // reset rotation matrix
transformation = Matrix.CreateRotationZ(modelZRotation); // reset rotation matrix
}

Any help would be great.


Re: XNA Game Studio Express Texture showing up black?

Kyle_W

At one point I tried to apply a texture with a BasicEffect and I was never able to get it to work. I recommend that you apply the texture using an Effect instead as described here:

http://msdn2.microsoft.com/en-us/bb195020.aspx

If you get the same results with an Effect, then I would suspect that the vertices of your model did not have a proper set of UV coordinates exported on them from Blender.





Re: XNA Game Studio Express Texture showing up black?

SnOrfus

I've seen that page before and I worked through it... I can render that cube just fine, but the problem I run into with that method is that I'm not manually setting up the vertices; I'm loading a model, and I don't know how to grab that kind of data to try to pass to "DrawIndexedPrimitive".

I've also gone through the SpaceWar game as well but it's so sloppy and disorganized that I can't wrap my head around the flow of it.




Re: XNA Game Studio Express Texture showing up black?

dczraptor

Instead of manually setting all the lighting properties, try just calling e.EnableDefaultLighting(); and see what you get. Then if that doesn't work, check to see if you're setting any strange render states (blending states, etc). I've gotten textures rendered with basiceffect with no problem. Here are the settings i used:

basicEffect = new BasicEffect(graphicsDeviceService.GraphicsDevice, null);
basicEffect.Alpha = 1.0f;
basicEffect.EnableDefaultLighting();
basicEffect.AmbientLightColor = Color.White.ToVector3();
basicEffect.DiffuseColor = Color.White.ToVector3();
basicEffect.TextureEnabled = true;
basicEffect.Texture = texture;
basicEffect.World = Matrix.CreateTranslation(position);
basicEffect.View = camera.View;
basicEffect.Projection = camera.Projection;






Re: XNA Game Studio Express Texture showing up black?

SnOrfus

hmm... no dice... with that code the sphere looks severely over-exposed.




Re: XNA Game Studio Express Texture showing up black?

Kyle_W

I agree that the sample is confusing since typically you would want to use a model rather than triangle primitives. However it's even easier to use an Effect with a model than with triangle primitives. All you have to do is load the Effect with the ContentManager, load the Model, assign the Effect to the appropriate MeshPart(s) like this:

myModel.Meshes[0].MeshParts[0].Effect = myEffect;

Then set myEffect.CurrentTechnique to the appropriate technique, and set any other required effect parameters. Finally, you draw the model by calling myModel.Meshes[0].Draw() My understanding is that the Draw() call should automatically iterate through the passes of the technique without a need for you to do it in your code, but I could be wrong about that.