Ok, I got home and I tried to enable the zbuffer. I called:
SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE)
Then, I disable culling, so it should, in theory, draw all the triangles, but only if the pixel is supposed to be in front. Basically, the same thing that backface culling does, right? Well, that didn''t work. So I also tried adding:
SetRenderState(D3DRS_ZFUNC, D3DCMP_LESS)
and even
SetRenderState(D3DRS_ZFUNC, D3DCMP_GREATER)
and it still doesn''t work. Could this be a problem with my video card? Has anyone else done the tutorial at wazoo''s website? Anyone else have this problem? Thanks for your time!
"I kinda think, therefore, I kinda... am?"
'CullMode' or 'The Man With X-Ray Vison!'
Correct me if I''m wrong, but in order to enable zbuffering in DX8, you have to enable it through the display paremeters. Anyways, here''s what the tutorial says.
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof(d3dpp) );
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = d3ddm.Format;
Now, to enable the zbuffer, you have to do this:
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = d3ddm.Format;
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
Now, if I''m correct, dx will automatically enable the zbuffer. (although if this doesn''t work I would suggest trying SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE) after creating the d3ddevice. )
Hope this helps
-Doddler
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof(d3dpp) );
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = d3ddm.Format;
Now, to enable the zbuffer, you have to do this:
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = d3ddm.Format;
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
Now, if I''m correct, dx will automatically enable the zbuffer. (although if this doesn''t work I would suggest trying SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE) after creating the d3ddevice. )
Hope this helps
-Doddler
Oh my, I almost forgot something. As an addition to my code, your going to get some pretty odd artifacts if you don''t clear you zbuffer like this:
d3ddev->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0 );
-Doddler
d3ddev->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0 );
-Doddler
Thanks for the help. I didn''t try enabling it in the Present Parameters. I''ll try that when I get home. I did get that weired thing you mentioned in the second post, but I fiugure it had to do with that. That makes me think that the z-buffer was enabled, though. Could it possibly have to do with the way that the index buffer is ordered? I have a basic understanding of the index/vertex buffers. I will try to play around with them when I get home. I guess that it''s not really that big of a deal. I can always enable backface culling and that works, but it seems rather odd to me. Maybe just a quirk on my machine.
"I kinda think, therefore, I kinda... am?"
"I kinda think, therefore, I kinda... am?"
Ok, I want to say thank you to everyone who helped me! I got home and now it works! I had to enable the z buffer in the present parameters and then it worked. I learned a lot about how DX draws 3D and I don''t think I will ever have this problem again. Now, just another quick question; Is this normal on most video cards? In the tutorial it doesn''t have any of the z-buffer information. If most people were to type in the tutorial, would they have the same problem? Thanks for your time!
"I kinda think, therefore, I kinda... am?"
"I kinda think, therefore, I kinda... am?"
well, yeah. From what I''ve read of that tutororial, yeah. The reason you had the problem, was with the way D3D drew your triangles. Some one please correct me if any of my information is wrong. Also note that my explanation is based on the comparison between the two images you posed. First off, when you look at a cube, if you don''t draw any of the sides that are that arn''t facing towards you, you won''t have any overdraw (won''t draw over any currently written pixels). That''s just the nature of cubes. The people that initially did the tutoral probably knew this and took advantage of it, since they don''t actually change the cull mode. But now look at the image where you had cullmode set to none. Setting the cullmode to none means that you draw the triangle no matter which direction it''s facing (for example, initially, all the triangles of the cube would be facing away from it''s center). If d3d had drawn the side facing towards you first, drawing the rest of the faces would have drawn over that first face. You understand what I mean? Think of it like pasting 2d sprites. If you draw your front face first, and draw the back one next, the back of the cube is going to cut off the front. You can fix this with two different methods. One, is sorting all your triangles in the scene from back to front, and draw them in that order. Unfortunately, that takes quite a bit of code, and we just want to make that cube look normal. The other method, zbuffering, you already now know about. What it does is that when it draws a pixel, it also records it''s depth to a buffer. When it draws the pixel, if it''s not closer to you than the last one that was drawn, then it doesn''t draw it. This way, you won''t get any effects like what you had with your cube. Anyways, I think I got a little carried away, but oh well. Anyways, your problem was with the very nature of d3d (and opengl too, I''m guessing), not with any video card. Hope this let''s you understand a bit more about what''s going on behind the scenes.
-Doddler
-Doddler
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement