I'm trying to load the airplane formthe dx9 samples. For some reason it gets drawn weirdly: http://img20.imageshack.us/my.php image=dx9thinger4vh.jpg
Here's how I'm doing it:
public class Model
{
Mesh mesh = null;
Material[] materials = null;
Texture[] textures = null;
public Model()
{
}
public Model(Device device, String filepath)
{
ExtendedMaterial[] tempMaterials;
mesh = Mesh.FromFile(filepath, MeshFlags.IbManaged, device, out tempMaterials);
if (tempMaterials != null && tempMaterials.Length > 0)
{
materials = new Material[tempMaterials.Length];
textures = new Texture[tempMaterials.Length];
for(int i = 0; i < tempMaterials.Length; i++)
{
materials
materials
if( tempMaterials
{
textures
}
}
}
}
public void Draw(Device d)
{
for (int i = 0; i < materials.Length; i++)
{
d.Material = materials
d.SetTexture(0, textures
mesh.DrawSubset(i);
}
}
}

I loaded a mesh and it gets drawn weirdly....
Gerry Thompson
//24 bits for the depth and 8 bits for the stencil
presentParams.AutoDepthStencilFormat = DepthFormat.D24S8;
//Let direct3d handle the depth buffers for the application
presentParams.EnableAutoDepthStencil = true;
Also change your near clipping plane of your projection matrix to 1.0f instead of 0.1f
device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI/4, 1.0f, 1.0f, 1000.0f);
I hope this helps.
Take care.
Travis Bickle
Anyway, here's what I have to set up the device:
public bool InitializeGraphics()
{
try {
PresentParameters presentParams = new PresentParameters();
presentParams.Windowed = true;
presentParams.SwapEffect = SwapEffect.Discard;
// Create the device
device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams);
// Setup the event handlers for the device
device.DeviceLost += new EventHandler(this.InvalidateDeviceObjects);
device.DeviceReset += new EventHandler(this.RestoreDeviceObjects);
device.Disposing += new EventHandler(this.DeleteDeviceObjects);
device.DeviceResizing += new CancelEventHandler(this.EnvironmentResizing);
// renderstates
device.RenderState.Lighting = false;
device.RenderState.ZBufferEnable = true;
device.Transform.Projection = Matrix.PerspectiveFovLH((float)(Math.PI / 3), (float)(4/3), 0.1f, 1000f);
model = new Model[1];
model[0] = new Model(device, "airplane 2.x");
return true;
} catch (DirectXException) {
return false;
}
}
As you can see, zbuffer is enabled, lighting is off (I'll figure that out later). As for the missing textures, I'm not concerned about that as much as I am about drawing the mesh correctly to begin with.
Jharker1987
AmcoDevTeam
Moustafa
Your present parameter seem to have declare the Z-Buffer, that's a good thing
Now you need to tell your device to use it, this way :
device->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);
device->SetRenderState(D3DRS_ZWRITEENABLE, TRUE);
device->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESSEQUAL);
When we render 3D geometry to the screen it is projected onto the 2D screen space and hence we lose the z (depth) value. It is useful however when rendering to store a depth value for each pixel on the screen to avoid drawing pixels when something is behind something else.
Example
To enable the z buffer for tests and writes we could do this:
device->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);
device->SetRenderState(D3DRS_ZWRITEENABLE, TRUE);
device->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESSEQUAL);
This site is very helpful :
http://www.toymaker.info/Games/html/render_states.html
Tomas Frojdo
It look like you don't have Z-buffer Enable, so each triangle are drawn on top of each other, Maybe you didn't set a Z-buffer in the present param or Z-Enable is not set to True
To draw you need 3 matrix, Proj, View and Word and they most all be setup properly
Mesh like the plane has texture and material so when you don't have a texture for a subset you have to Set a material like you do for your texture, your white propeler may aslo be because one texture file is missing, I think the plane use 2 texture file (another texture might be found in the media directory) You can add extention TXT to your x File and open it in Notepad and Search for BMP, TGA or JPG extension in the material section near the end this will tell you which texture the X file use (change back to X extension after reading your info