Jump to content
  • Advertisement

Archived

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

BrianH

D3D Rendering Woes

This topic is 6625 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

I am experiencing some incorrect rendering results in D3D. Here is what I am doing. 1. I created a teapot in 3DStudio Max and export it to a .3ds file 2. When I load the .3ds file I... a. switch z and y in the vertices becuase it seems that 3DStudio uses y as depth going into the screen instead of z. b. flip the order that the faces are defined, i.e. A,B,C in the file should be C,B,A, This defines them clockwise the way D3D wants them. 3. then, I plop the vertices in an array that defines the faces (i am using a non-indexed triangle list). I am also using non-transformed, non-lit vertices (D3DFVF_VERTEX) 4. I calculate the normals for the faces using... vn1 = B - A; vn2 = C - B; vn = CrossProduct(vn1,vn2); vn = Normalize(vn); 5. the render states I set are -> cullmode CCW, zbuffer on, lighting on, gouraud. 6. I set the material to... //setup a material D3DCOLORVALUE black = {0.0f,0.0f,0.0f,1.0f}; D3DCOLORVALUE col = {0.0f,0.0f,0.4f,1.0f}; D3DCOLORVALUE coldim = {0.0f,0.0f,0.1f,1.0f}; D3DMATERIAL7 d3dmat; d3dmat.diffuse = col; d3dmat.ambient = coldim; d3dmat.specular = col; d3dmat.emissive = black; d3dmat.power = 2.0; 7. I turn on a point light source of white light. 8. i then render the teapot using... g_dev->Clear(1,&r,D3DCLEAR_TARGET,0x00000000,0,0); g_dev->Clear(1,&r,D3DCLEAR_ZBUFFER,0x00000000,1.0f,0); g_dev->DrawPrimitive(D3DPT_TRIANGLELIST,D3DFVF_VERTEX,g_verts, g_numverts, 0); 9. The result I get looks somewhat correct (shaded, lighting looks good) but the spout, handle, and lid-knob seem to be rendered on top of everything, in other words the depth is wrong. For example, when facing the teapot on the side the spout is, i can see the handle showing through from behind. here is a screen shot: www.eng.uc.edu/~bhoffer/teapot1.jpg 10. I tried it with other primitives like spheres, boxes, and cones and they all seem to work fine. the only difference I can see between the objects is that these simpler ones are all completely convex. I have thought of the following which may be wrong... A. zbuffer is not created (although i get no errors) or is for some reason not functioning properly B. maybe i am not specifying the material correctly and alpha is allowing thing to be rendered through. C. Something incorrect thoughout my entire loading of 3ds files to putting them into the vertex array and calculating normals. anyway, i know this is alot of info but i thought the more i could narrow it down, the better chance of getting good help. thanks in advance, BrianH

Share this post


Link to post
Share on other sites
Advertisement
In addition to the above, I just ran my app without a zbuffer and it did the exact same thing. I am now almost certain that it is a zbuffer problem. I rendered a torus and the same type of thing happens. I also set the zbuffer state to true before rendering.

BrianH

Share this post


Link to post
Share on other sites
WOOO HOOO! I figured it out. After you create your z-buffer, you must do D3DDev7->SetRenderTarget(back) to reset some stuff. Geez, 2 days of bashing my head into the desk for this (and it was right there in my book)!

BrianH

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!