Jump to content
  • Advertisement
Sign in to follow this  

invisible mesh in managed DX

This topic is 4553 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 having a problem with a mesh not displaying when I render it. Currently I have a skybox mesh that loaded and rendered without any problems, but when I apply the same technique to another simple mesh it seems to be invisible. After debugging the code for 2 days and searching all over the net I don't seem to be getting any closer to fixing it. Are there any typical problems a noob might face when loading and rendering meshes? Also... I loaded the same mesh using "Tutorial 6: Using Meshes" of the june sdk and it worked fine. So it must be a problem w/ my code. Here is the basic code i'm using to load and render the mesh.
public void load(Device device, String path)
            ExtendedMaterial[] mtrls;
            String texPath = "../data/saucer/";
            thisMesh = Mesh.FromFile(path, MeshFlags.Managed, device, out mtrls);            
            // Store the mesh materials and textures (mtrls is a list of extendedMaterials)
            if ((mtrls != null) && (mtrls.Length > 0))
                myTextures = new Texture[mtrls.Length];
                shaderList = new  Material[mtrls.Length];

                for (int i = 0; i < mtrls.Length; i++)
                    // Create the texture                    
                    if (mtrls.TextureFilename != null)
                        {myTextures = TextureLoader.FromFile(device, texPath + mtrls.TextureFilename);
                    shaderList = mtrls.Material3D;                                         
                    shaderList.Ambient = shaderList.Diffuse;
                }//end for loop
            }//end if
        }//end load

        public void render(Device device)
            //tell the device to switch to the current model's transform
            device.Transform.World =
                Matrix.Scaling(scale) *
                Matrix.RotationYawPitchRoll(rotation.X, rotation.Y, rotation.Z) *

            for(int i = 0; i < shaderList.Length; i++) {
                device.Material = shaderList;
                device.SetTexture(0, myTextures);
        }//end render

The main engine class calls the render function above during the render phase.

Share this post

Link to post
Share on other sites
Ok, so I figured out the cause of the invisible mesh!

When I render my skybox I disable the zbuffer and lighting like so:

device.RenderState.ZBufferEnable = false;
device.RenderState.ZBufferWriteEnable = false;
device.RenderState.Lighting = false;
//render stuff

After rendering the skybox I was switching the zbuffer back on by setting the above properties to true (which prevents the mesh from showing up). If I leave the zbuffer props commented out the next mesh I render is visible. Any ideas on why this might be happening?

Share this post

Link to post
Share on other sites
I guess I will go ahead and post this since it might help someone else.

My Whole problem was that I set the nearclip plane to .1f. I read on another thread that most of the accuracy of the Zbuffer is used within the first 25% of the range so lower nearclip values tend to screw things up.

Once I changed this to 1f everything works like a charm.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!