Jump to content
  • Advertisement
Sign in to follow this  
whereisumar

C# Direct3D 9.0

This topic is 4436 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 everyone, I have a question. I have started using direct3d with C#. I don't understand why my rendering is not displaying things in order. For instance, a box that is behind a pyramid, is actually being displayed as being in front, the geometry is not hiding what's behind it. I have enabled the zbuffer with device.RenderStates.ZBufferEnable = true in the initialization, it still is not working!! I'm so frustrated. Someone please help me out. Am I missing something? I've worked for a month on a pretty decent ASE file loader loading transforms, meshanimation, camera and light controls etc. This one thing is just messing it up. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
You didn't say if you set a depth buffer format so try this instead:

PresentParameters pp = new PresentParameters();
pp.AutoDepthStencil = DepthBufferFormat.D16
pp.EnableAutoDepthStencil = true;


I don't remember the exact names for the property and enum that hold the depth buffer formats, but it's something to that effect, so it shouldn't be too hard to find. Hope this helps.

-AJ

Share this post


Link to post
Share on other sites
Hi,

You'll need to provide a proper format under the AutoDepthStencilFormat in the PresentationParameters, and also set AutoDepthStencil to true.

Valid formats would be any depth/stencil format (namely, D16, D32, or D24S8).

Hope this helps.

Edit: beaten, oh the noes.

Share this post


Link to post
Share on other sites
Hi, well, i added the following lines as suggested

presentParams.AutoDepthStencilFormat = DepthFormat.D16; presentParams.EnableAutoDepthStencil = true;

But it still is not working, there was no difference.

Is there a specific DepthFormat I have to use, or can any one work?

Is it a problem with c#? This may sound like a foolish question, but are there any bugs or incomplete sections for the Direct3D API for C#?

Share this post


Link to post
Share on other sites
Are you sure the location of the objects is correct. Let's see some code to [smile].

-AJ

Share this post


Link to post
Share on other sites
Hi, the location of the objects is correct, i'm importing straight from 3d studio .ASE format. I double check the order by moving the camera around in my engine, so i know what is infront and behind.

Does the order of the device.DrawPrimitives have to be in order too, or just once per output direct3d checks the buffer after all the device.drawprimitives have been called for that frame?

What type of code would help you help me?

Again, thanks a log guys.

Share this post


Link to post
Share on other sites
Quote:
Original post by whereisumar
Hi, the location of the objects is correct, i'm importing straight from 3d studio .ASE format. I double check the order by moving the camera around in my engine, so i know what is infront and behind.

Does the order of the device.DrawPrimitives have to be in order too, or just once per output direct3d checks the buffer after all the device.drawprimitives have been called for that frame?

What type of code would help you help me?

Again, thanks a log guys.


The order of device.DrawPrimitives shouldn't matter, I don't think, but it helps for efficiency's sake. The code that would help out would probably be any rendering code and code that handles positioning of the objects in the world.

-AJ

Share this post


Link to post
Share on other sites
Hi, well below is some related code to my problem.

PresentParameters presentParams = new PresentParameters();
presentParams.Windowed = true;
presentParams.SwapEffect = SwapEffect.Discard;

device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams);
device.RenderState.Lighting = true;
presentParams.AutoDepthStencilFormat = DepthFormat.D16;
presentParams.EnableAutoDepthStencil = true;
device.RenderState.ZBufferEnable = true;

device.RenderState.CullMode = Cull.CounterClockwise;

That's all in the initialization. Below is code regarding positioning, this may be a bit confusing and an overload, because it's taking transformations into account.

while (!CorrectKeyFrameFound)
{
if (Ticks >= TMAnimation.PosTrack[KeyFrame].Frame && Ticks < TMAnimation.PosTrack[KeyFrame+1].Frame)
{
CorrectKeyFrameFound = true;
CurrentFrame = KeyFrame;
}
KeyFrame++;
}
Magnitude = (Ticks - TMAnimation.PosTrack[CurrentFrame].Frame) / 160;
Pos.X = TMAnimation.PosTrackI[CurrentFrame].Pos.X;
Pos.Y = TMAnimation.PosTrackI[CurrentFrame].Pos.Y;
Pos.Z = TMAnimation.PosTrackI[CurrentFrame].Pos.Z;

M.M41 += Pos.X;
M.M42 += Pos.Y;
M.M43 += Pos.Z;

device.Transform.World = M;

The above code is fragments from the .Draw() function. Each object has it's own draw method.

Hope this helps. I really still can't see what i'm doin wrong

Share this post


Link to post
Share on other sites
Are you clearing the z-buffer by including ClearFlags.ZBuffer in your Device.Clear method?

Share this post


Link to post
Share on other sites
protected virtual void Render()
{
if (device != null) {
device.Clear(ClearFlags.Target, Color.Black, 1.0f, 0);
device.Clear(ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
device.BeginScene();
GameObject.Draw(device, Ticks);
DateTime StartTime = DateTime.Now;
while (DateTime.Now.Ticks < StartTime.Ticks + 191325);
Ticks+=160;
device.EndScene();
device.Present();
}
}

Hi, well i added this line, i'm almost 100% sure i'm doing this wrong, this is the render method. Is this what you meant? Also, now when i run it, it just gives me an error and does not start at all.

How do you hide geometry!?!?!? i'm goin crazy.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!