Jump to content
  • Advertisement
Sign in to follow this  
Xavyiy

Mesh drawing problem

This topic is 4122 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

Hi all!, I've some problems for drawing textured mesh with DirectX / C#, here is a shot: Free Image Hosting at www.ImageShack.us And the drawing code:
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{

      device.Clear(ClearFlags.Target, Color.DarkSlateBlue , 1.0f, 0);

      device.Transform.World =  Matrix.Translation(new Vector3(5,5,-65) * Matrix.Scaling(2,2,2);
    device.RenderState.Lighting = false;

      device.BeginScene();

      this.DrawMesh(spacemesh, spacemeshmaterials, spacemeshtextures);
          
      device.EndScene();
 
      device.Present();
  
      this.Invalidate();
}
the mesh load/draw code:
private void LoadMesh(string filename, ref Microsoft.DirectX.Direct3D.Mesh mesh, ref Material[] meshmaterials, ref Texture[] meshtextures, ref float meshradius)
     {
             ExtendedMaterial[] materialarray;
             mesh = Mesh.FromFile(filename, MeshFlags.Managed, device, out materialarray);
 
             if ((materialarray != null) && (materialarray.Length > 0))
             {
                 meshmaterials = new Material[materialarray.Length];
                 meshtextures = new Texture[materialarray.Length];
 
                 for (int i = 0; i < materialarray.Length; i++)
                 {
                     meshmaterials = materialarray.Material3D;
                     meshmaterials.Ambient = meshmaterials.Diffuse;
 
                     if ((materialarray.TextureFilename != null) && (materialarray.TextureFilename != string.Empty))
                     {
                     
                     	meshtextures = TextureLoader.FromFile(device, materialarray.TextureFilename.Replace(".GIF",".jpg"));
                     }
                 }                
             }
 
             mesh = mesh.Clone(mesh.Options.Value, CustomVertex.PositionNormalTextured.Format, device);
             mesh.ComputeNormals();
 
             VertexBuffer vertices = mesh.VertexBuffer;
             GraphicsStream stream = vertices.Lock(0, 0, LockFlags.None);
             Vector3 meshcenter;
             meshradius = Geometry.ComputeBoundingSphere(stream, mesh.NumberVertices, mesh.VertexFormat, out meshcenter) * scaling;
             vertices.Unlock();
         }
 
         private void LoadMeshes()
         {        
             LoadMesh("racer.x", ref spacemesh, ref spacemeshmaterials, ref spacemeshtextures, ref spacemeshradius);
         }
         
         private void DrawMesh(Mesh mesh, Material[] meshmaterials, Texture[] meshtextures)
         {
             for (int i = 0; i < meshmaterials.Length; i++)
             {
                 device.Material = meshmaterials;
                 device.SetTexture(0, meshtextures);
                 mesh.DrawSubset(i);
             }
         }
and the car should be like this: I need your help :)! Thanks EDIT: Please remember to use 'source' tags in future... [Edited by - jollyjeffers on June 9, 2007 4:42:41 PM]

Share this post


Link to post
Share on other sites
Advertisement
device.Clear(ClearFlags.Target, Color.DarkSlateBlue , 1.0f, 0);

This line does not clear the depth buffer, is this intentional? Have you configured one? Your screenshot looks like the results of no/incorrect depth buffering. Simply set it up (or reinstate the clear operation) and you should be sorted [smile]


hth
Jack

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!