Re: something wrong with meshes

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


Date: Thu, 7 Oct 2004 13:56:16 -0700

I completely agree, its a problem with the code. I have spend last night and
this morning comparing the code and I cant see a anything that I am doing
differently, which is why I posted it.

Jason

"Philip Taylor [ATI]" <ptaylor@online.newsgroup-poster.ati.com> wrote in
message news:uL2z14KrEHA.3116@TK2MSFTNGP10.phx.gbl...
> if the samples dont do this, and your code does - this is obviously a
> problem in your code and not with DX or with Managed-DX.
>
> go thru the samples line by line and see how they set up rendering. then
> look at your code.
>
> "Jason" <Jason@mobiform.com> wrote in message
> news:OAcElZKrEHA.2924@TK2MSFTNGP12.phx.gbl...
> > The samples do not show the same problem.... I also suspect the zbuffer,
> but
> > I think its setup properly. The posted code shows everything that is
done
> > reguarding directX so if you have something I can try I will throw it in
> and
> > see what happens
> >
> > Jason
> >
> > "Philip Taylor [ATI]" <ptaylor@online.newsgroup-poster.ati.com> wrote in
> > message news:%23GCeOMKrEHA.2436@TK2MSFTNGP10.phx.gbl...
> > > is the zbuffer properly set up and working?
> > >
> > > do the samples show the same problem?
> > >
> > > "Jason" <Jason@mobiform.com> wrote in message
> > > news:e7awSHKrEHA.3896@TK2MSFTNGP15.phx.gbl...
> > > > 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();
> > > >
> > > >
> > > >
> > > > }
> > > >
> > > > }
> > > >
> > > >
> > >
> > >
> >
> >
>
>