Sign in to follow this  
BEHOLDER192875

Render .X file

Recommended Posts

I am rendering a ship using a .x file, but I can't get it to render correctly. If I set the stencil buffer to FALSE using D3DPRESENT_PARAMETERS, then the model renders correctly, otherwise it will render faces in a non-z order. I have the z-buffer enabled too. It should render it correctly, but I'm at a loss at this point. Any suggestions?

Note: I am using clear correctly.

Share this post


Link to post
Share on other sites
Just a thought. If you can't see the model at all when you are rendering it, it may be because of the culling order. try to disable backface culling. You can do that in the main code or a shader file if you are using one.

Let me know if you don't know how to do that. Or you could just reverse the order of of the index buffer for each triangle in the .X file or in your code while your loading the model.

I'm not sure what version of directx your using, but if your using directx 10 or 11, you might have your vertex layout wrong, So you should show what your vertex layout is if you have one.

Share this post


Link to post
Share on other sites
I was loading the X file using D3DXLoadMeshFromX(). It loads perfectly in meshviewer. I have the faces rendering in the correct winding (CCW). My best guess would be that the faces are loading incorrectly, but then the question becomes, why would a function internal to DirectX work in the meshviewer, but not in code?

Edit: I see the model, I have the lighting correct, and I'm using DirectX 9.

Share this post


Link to post
Share on other sites
it wont be D3DXLoadMeshFromX() thats causing the problem, i assume thats what the model viewer uses also

can you provide your loading code, render code and the d3dParams setup, i would imagine it would be in the params section if lighting is not an issue, and having the z-buffer enabled means that rendering the subsets out in an incorrect order should matter

Share this post


Link to post
Share on other sites
I figured it out through another post that I found from years ago (took me nearly 4 hours). Anyway, I had everything correct except one thing.

Do NOT set a perspective near-z to 0.0f. This will cause the z-buffer to not have the accuracy required. Even setting the near-z to a relatively close to zero number is still probably a bad idea because you could still get the same artifacts. I would suggest going to about 5% of the far-z.

Great learning experience for me, and I hope this will help others in the future.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this