Original Post
Hi,
I have posted a similar thread a week ago but still havent solve my problem...
I''m currently working on a 3D app that can render a window in 3D from a 2D image of the shape of the window, with a user defined width, height, depth and border size. The window also has a frame, what holds the window in place, which is also generated from a 2d bitmap of the frame. The frame is placed on the inner side of the window but my problem is that, when you rotate the window, the frame is still visible through the window border even if it should be hidden by the border.
heres some shots so you can see for yourself...
squarewindow_nolighting_frontview.jpg
squarewindow_nolighting_sideview.jpg
the shots above have ligthing disabled and have no texture, only a color value, the grey object is the frame and the white object is the border of the window, and as you can see in the side view of the window, they frame is appearing through the border =/
I''ve been trying to solve this problem for a couple of days now and still can''t find a solution... the problem seems to be with the depth buffer but i can''t figure it out...
Here''s the code i''m using to Init Direct3D
public static bool Init( System.Windows.Forms.Control renderWindow )
{
try
{
Graphics.presentParams = new PresentParameters();
Graphics.presentParams.Windowed = true;
Graphics.presentParams.SwapEffect = SwapEffect.Flip;
Graphics.presentParams.EnableAutoDepthStencil = true;
Graphics.presentParams.AutoDepthStencilFormat = DepthFormat.D16;
Graphics.device = new Device( 0 , DeviceType.Hardware, renderWindow, CreateFlags.SoftwareVertexProcessing, Graphics.presentParams );
Graphics.device.RenderState.CullMode = Cull.Clockwise;
Graphics.device.RenderState.Lighting = false;
Graphics.device.RenderState.ZBufferEnable = true;
return true;
}
catch (DirectXException)
{
return false;
}
}
It''s in c# and I know most of you are using c++ but you should still be able to understand what''s going on... if you know how to solve it in c++, you can post your answer in c++, I''ll be able to convert it to c#...
In the code above, the Graphics class is my class where I have encapsulated all the DirectX stuff and it contains only static methods and variables.
My objects are generated and stored in VertexBuffers associated with IndexBuffers and I''m rendering them using DrawIndexedPrimitive with TriangleList
Another thing I forgot to mention is that If I don''t put a depth bias nothing renders... The border (white object) needs a depth bias of 12.94 to be visible and the frame (grey object) needs a depth bias of 3.94 to be visible... below that both object are invisible at all times.
The border is rendered before the frame, If I render the frame before the border, the inverse is happening and the frame is hidden when it shouldnt...
I have also tried to ply with the far and near view plane to have more precision in the z-buffer but it doesn''t seem to solve the problem...
Here''s my setup matrices function
public static void SetupMatrices( int windowWidth, int windowHeight )
{
Graphics.device.Transform.View = Matrix.LookAtLH( new Vector3( 0.0f, 0.0f, -50.0f ), new Vector3( 0.0f, 0.0f, 0.0f ), new Vector3( 0.0f, 1.0f, 0.0f ) );
Graphics.device.Transform.Projection = Matrix.PerspectiveFovLH( (float)Math.PI / 4, Convert.ToSingle(windowWidth)/Convert.ToSingle(windowHeight), 1.0f, 100.0f );
}
and my render functions
//window render
public void Render()
{
Graphics.device.RenderState.DepthBias = 12.94f;
if( this.shape != null )
{
this.shape.Render();
}
Graphics.device.RenderState.DepthBias = 3.94f;
if( this.frame != null )
{
this.frame.Render();
}
}
//shape render
public void Render()
{
Graphics.device.VertexFormat = CustomVertex.PositionNormalColored.Format;
Graphics.device.Indices = this.indexBuffer;
Graphics.device.SetStreamSource( 0, this.vertexBuffer, 0 );
Graphics.device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, this.windowBuffer.Length * 2, 0, (this.indices.Count/3)*2 + this.windowBuffer.Length*2 );
}
//frame render
public void Render()
{
Graphics.device.VertexFormat = CustomVertex.PositionNormalColored.Format;
Graphics.device.Indices = this.indexBuffer;
for( int i = 0; i < this.vertexBuffers.Length; i++ )
{
if( this.vertexBuffers[i] != null )
{
Graphics.device.SetStreamSource( 0, this.vertexBuffers[i], 0 );
Graphics.device.DrawIndexedPrimitives( PrimitiveType.TriangleList, 0, 0, 8, 0, 12 );
}
}
}
Hope you can help me out...
If you need more info on some things, just ask
Stéphane Ross
Game Gurus Entertainment