Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

sross

Need Help with Depth Buffer plz...

This topic is 5541 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
I don''t understand the code that well, but I can offer some suggestions.

First of all, I don''t know why you are using a depth bias. It was always mentioned on the C++ DirectX Dev mailing list that depth biasing is an evil thing since it is not consistant across all hardware.

Second, I don''t see any calls to clear. Are you clearing both the depth beffer and the render target?

Also check to see if you get the same results on a hardware defice as well as the refras.

And of course make sure that you have the latest DirectX libs 9.*b and the most updated video card.

Other than that I don''t know what is going on...

Good luck!
/jk

Share this post


Link to post
Share on other sites
You were right, I just found my stupid error... sigh and wanted to post it here to say I found the problem... I forgot to clear the z buffer sigh

It was still not working after, but I took off the zbias and everything works fine...

my clear function was in the general render function of the form which i didnt included in the code above... I searched everywhere in my code except there... until I fell on that checking for something else...

I feel really stupid right now...

well at least it works

thx anyway

[edited by - sross on August 15, 2003 4:11:48 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!