something wrong with meshes

From: Jason (Jason_at_mobiform.com)
Date: 10/07/04


Date: Thu, 7 Oct 2004 12:14:06 -0700

I'm having a little problem with mesh rendering, it looks almost like stuff
is rendered in backwards order. cullmode seems to have the correct effect,
but still some things appear ontop of other things they should not be. In
the mesh I am using I have a billboard, there are polls along the back that
should be bhind everything, yet they appear ontop of the billboard... but
behind a litte platform in front of the billboard. when the object is
rotated its the same order, platform, poles, billboard last.

I pulled out all the device creation rendering code to put it into one place
thinking it might be something else rendering changing the state a messing
it up but I get the same results. Maybe someone can spot what I am doing
wrong?

Its c# code, I made a button in a default project, added a button and below
is the button response function... I think you juat need an .x and to add
the direct references to the project.

Thanks

J

//--------------------------------------

private void button1_Click(object sender, System.EventArgs e)

{

System.Windows.Media3D.RenderManager rm =
System.Windows.Media3D.RenderManager.GetSingleton();

//create device

Device device;

// Set our presentation parameters

PresentParameters presentParams = new PresentParameters();

presentParams.Windowed = true;

presentParams.SwapEffect = SwapEffect.Discard;

presentParams.AutoDepthStencilFormat = DepthFormat.D16;

presentParams.EnableAutoDepthStencil = true;

presentParams.PresentFlag = Microsoft.DirectX.Direct3D.PresentFlag.None;

/*//no change

presentParams.Windowed = true;

presentParams.BackBufferCount = 0;

presentParams.MultiSample = MultiSampleType.None;

presentParams.MultiSampleQuality = 0;

presentParams.SwapEffect = SwapEffect.Discard;

presentParams.EnableAutoDepthStencil = true;

presentParams.AutoDepthStencilFormat = DepthFormat.D16;

presentParams.PresentFlag = PresentFlag.None;

presentParams.BackBufferWidth = this.Width;

presentParams.BackBufferHeight = this.Height;

presentParams.BackBufferFormat = Format.R5G6B5;

presentParams.FullScreenRefreshRateInHz = 0;

presentParams.PresentationInterval = PresentInterval.Immediate;

presentParams.DeviceWindow = this;

*/

// store our default adapter

int adapterOrdinal =
Microsoft.DirectX.Direct3D.Manager.Adapters.Default.Adapter;

// get our device capabilities so we can check

Caps caps = Manager.GetDeviceCaps(adapterOrdinal, DeviceType.Hardware);

CreateFlags createFlags;

if (caps.DeviceCaps.SupportsHardwareTransformAndLight)

{

createFlags = CreateFlags.HardwareVertexProcessing;

}

else

{

createFlags = CreateFlags.SoftwareVertexProcessing;

}

if (caps.DeviceCaps.SupportsPureDevice)

{

createFlags |= CreateFlags.PureDevice;

}

device = new Device(adapterOrdinal, DeviceType.Hardware,

this,

createFlags, // CreateFlags.SoftwareVertexProcessing,

presentParams);

//===

//some default states

device.RenderState.CullMode = Cull.CounterClockwise;

device.RenderState.ZBufferEnable = true;

device.RenderState.ColorVertex = true;

device.RenderState.EmissiveMaterialSource = ColorSource.Material;

device.RenderState.ShadeMode = ShadeMode.Gouraud;

device.RenderState.AmbientMaterialSource = ColorSource.Material;

device.RenderState.AlphaFunction = Compare.GreaterEqual;

device.RenderState.AlphaTestEnable = true;

device.RenderState.ReferenceAlpha = 8;

device.RenderState.SourceBlend =
Microsoft.DirectX.Direct3D.Blend.SourceAlpha;

device.RenderState.AlphaBlendEnable = true;

device.RenderState.DestinationBlend =
Microsoft.DirectX.Direct3D.Blend.InvSourceAlpha;

device.SamplerState[0].MinFilter = TextureFilter.Linear;

device.SamplerState[0].MagFilter = TextureFilter.Linear;

device.SamplerState[0].MipFilter = TextureFilter.Linear;

device.RenderState.Lighting = true;

device.RenderState.SpecularEnable = true;

device.RenderState.Ambient = Color.Black;

//===

//load the mesh

Mesh m = Mesh.FromFile("BillBoard.X", MeshFlags.SystemMemory, device);

//setup camera

device.Transform.Projection = Matrix.PerspectiveFovLH(

0.67f,

4.0f/3.0f,

1.0f,

1500.0f);

device.Transform.View = Microsoft.DirectX.Matrix.LookAtLH( new Vector3(
0,50,-700), new Vector3( 0,0,0), new Vector3( 0,1,0) );

device.Transform.World = Matrix.Identity;

//default material

Material mat = new Material();

mat.Diffuse = Color.Blue;

mat.Ambient = Color.Red;

device.Material = mat;

//viewport

Viewport vp = new Viewport();

vp.X = 0;

vp.Y = 0;

vp.Width = this.Width;

vp.Height = this.Height;

device.Viewport = vp;

//default lights

device.Lights[0].Diffuse = Color.White;

device.Lights[0].Type = LightType.Directional;

device.Lights[0].Direction = new Vector3(0,0,1);

device.Lights[0].Commit();

device.Lights[0].Enabled = true;

//draw

device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.White, 1.0F, 0);

device.BeginScene();

m.DrawSubset(0);

device.EndScene();

device.Present();

}

}



Relevant Pages

  • managed mesh rendering problem
    ... I'm having a little problem with mesh rendering, ... yet they appear ontop of the billboard... ... PresentParameters presentParams = new PresentParameters; ... CreateFlags createFlags; ...
    (microsoft.public.win32.programmer.directx.graphics)
  • Re: Can Microsoft people answer my last post, please?
    ... Microsoft DirectX MVP 1998-2006 ... and a mesh. ... chapter of a book to disable texture colores and alpha. ... State the basis of your problem, i.e. when rendering a triangle list ...
    (microsoft.public.win32.programmer.directx.graphics)
  • Re: Can Microsoft people answer my last post, please?
    ... Problem rendering a list of triangle ... and a mesh. ... chapter of a book to disable texture colores and alpha. ... State the basis of your problem, i.e. when rendering a triangle list ...
    (microsoft.public.win32.programmer.directx.graphics)
  • Re: Do I have to redraw everything every frame / loading meshes
    ... Currently, each 3d window loads its own meshes, and as the static mesh is ... caching the result of rendering or simplifying the rendering. ... creating a secondary depth buffer and a secondary plain surface ...
    (microsoft.public.win32.programmer.directx.graphics)
  • Re: sml/nj open-gl interface
    ... rendering a static scene is less demanding than rendering an ... Most in-game LOD algorithms are array based. ... It starts with a high-precision square mesh and recursively ...
    (comp.lang.functional)