Jump to content
  • Advertisement
Sign in to follow this  
prometheus999

[.net] Materials go black if I display more than one mesh

This topic is 4695 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm using the cool example from the managed directx wiki. http://pluralsight.com/wiki/default.aspx/Craig.DirectX/MeshBasicsTutorial.html I created an object that took the mesh name and the device as arguments and have their own render methods. It works perfectly if I only make and render one Mesh but if I render two the materials seem to disapear, every surface of the mesh is totally black except for where there are textures, those parts render fine. What gives? Here's the bit of the constructor which has to do with the mesh: ExtendedMaterial[] exMaterials; mesh = Mesh.FromFile(Path.Combine(artPath, name), MeshFlags.SystemMemory, device, out exMaterials); if (textures != null) { DisposeTextures(); } textures = new Texture[exMaterials.Length]; materials = new Material[exMaterials.Length]; for (int i = 0; i < exMaterials.Length; ++i) { if (exMaterials.TextureFilename != null) { string texturePath = Path.Combine(artPath, exMaterials.TextureFilename); textures = TextureLoader.FromFile(device, texturePath); } materials = exMaterials.Material3D; materials.Ambient = materials.Diffuse; } and here's the render method: public void RenderMesh() { for (int i = 0; i < materials.Length; ++i) { if (textures != null) { someDevice.SetTexture(0, textures); } device.Material = materials; mesh.DrawSubset(i); } }

Share this post


Link to post
Share on other sites
Advertisement
Okay, here's an update on my progress. I used the example code in for materials in the directx wiki. Then I try to encapsulate this into an object so all I have to do is transform and then render the primitive. If I make the SetUpMaterials method a method of this new object and call it durning the constructor like so:

public GameObject(string color, Device device)
{
gameVertices = CreateVertexBuffer(device);
SetupMaterials(color, device);
}

both primitives have the same material. Which material it chooses seems to depend on which object is instatiated last.


link to article in question.
http://pluralsight.com/wiki/default.aspx/Craig.DirectX/MaterialsBasicsTutorial.html

Share this post


Link to post
Share on other sites
Problem solved. But I'm not sure why this makes a difference. I take out the if (textures != null) statement and always execute device.SetTexture(0, textures); I can render as many meshes as I like. But I think this means that there would be problems if I wanted to render a mesh without a texture.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!