Archived

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

Index buffer problem on G400?

This topic is 5583 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''ve been studying DirectX8 for a while now and started developing a simple terrain engine. However, I have some rather strange problems with it. The terrain appears to render fine on my GeForce3 but on my friend''s Matrox G400, the triangles are distorted somehow. Here are a few screenshots to illustrate the problem; http://paranoia.tuug.fi/~jh/tmp/g400_screen0000.JPG http://paranoia.tuug.fi/~jh/tmp/g400_screen0001.JPG http://paranoia.tuug.fi/~jh/tmp/g400_screen0003.JPG http://paranoia.tuug.fi/~jh/tmp/gf3ti200_screen0001.JPG http://paranoia.tuug.fi/~jh/tmp/gf3ti200_screen0002.JPG I have no idea if this is a common problem but I wasn''t able to find anything to help me by searching this forum and with Google. I''ll try to write a bit on what my code does in case it helps. First, I create one large vertex buffer for the entire terrain. These vertices are arranged into a plane 33 vertices wide, thus allowing me to form triangle strips with 64 triangles each. m_dev->CreateVertexBuffer(m_vcount*sizeof(vertex), D3DUSAGE_WRITEONLY, (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1), D3DPOOL_DEFAULT, &m_vbuffer); The vertex data looks like this; Vertex 0: (512.000, 0.000, 0.000), normal (0.000, 0.000, 1.000), mapping (0.000, 1.000) Vertex 1: (480.000, 0.000, 0.000), normal (0.000, 0.000, 1.000), mapping (0.031, 1.000) Vertex 2: (448.000, 0.000, 0.000), normal (0.000, 0.000, 1.000), mapping (0.063, 1.000) Vertex 3: (416.000, 0.000, 0.000), normal (0.000, 0.000, 1.000), mapping (0.094, 1.000) ... Vertex 31: (-480.000, 0.000, 0.000), normal (0.000, 0.000, 1.000), mapping (0.969, 1.000) Vertex 32: (-512.000, 0.000, 0.000), normal (0.000, 0.000, 1.000), mapping (1.000, 1.000) Vertex 33: (512.000, 32.000, 0.000), normal (0.000, 0.000, 1.000), mapping (0.000, 0.996) Vertex 34: (480.000, 32.000, 0.000), normal (0.000, 0.000, 1.000), mapping (0.031, 0.996) ... Next, I create an index buffer which references vertices for one triangle strip. m_dev->CreateIndexBuffer(2*m_vwidth * sizeof(DWORD), D3DUSAGE_WRITEONLY, D3DFMT_INDEX32, D3DPOOL_DEFAULT, &m_ibuffer); I fill the index buffer with values for one complete strip of the terrain; {0, 33, 1, 34, ... , 32, 65}. Finally, the terrain is rendered a strip at a time; m_dev->SetStreamSource(0, m_vbuffer, sizeof(vertex)); m_dev->SetVertexShader( (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1) ); m_dev->SetTexture(0, m_pTexture); m_dev->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE); m_dev->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); m_dev->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_CURRENT); m_dev->SetTextureStageState(0, D3DTSS_MAGFILTER, D3DTEXF_ANISOTROPIC); m_dev->SetMaterial(&m_matMaterial); for(UINT i=sfrom;i<(sfrom+scount);i++) { m_dev->SetIndices(m_ibuffer, m_vwidth*i); m_dev->DrawIndexedPrimitive(D3DPT_TRIANGLESTRIP, 0, m_vwidth*2, 0, (m_vwidth-1)*2); } m_dev->SetTexture(0, 0); m_dev->SetStreamSource(0, 0, 0); m_dev->SetIndices(0, 0); That''s it. I also have a problem on my card with nothing being rendered when I enable lighting (there is a point light source in the same location as the camera) but I assume it has nothing to do with the problem described above.

Share this post


Link to post
Share on other sites
Are you sure the G400 can use 32 bit indices?

I also see you use (m_vwidth)*2 as your vertice count (m_vwidth-1)*2 as your primitive count. This does not seem right. What exactly is m_vwidth?

[edited by - smanches on August 27, 2002 6:25:44 PM]

Share this post


Link to post
Share on other sites
Hmm, I''m not actually sure about 32bit indices on G400. At least for now I have no reason to use them as 16bit ones would suffice, so maybe I''ll give it a try. Thanks for the tip.

m_vwidth is the width of the terrain in vertices which in this case is 33. So, one triangle strip of the terrain has (m_vwidth-1)*2=64 triangles which index m_vwidth*2=66 vertices.

Decreasing the primitive count in the DrawIndexedPrimitive() call results in in triangles missing from the strip. This is slightly confusing as I thought that the _strip_ is the primitive and there''s only one of them to be drawn.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I''ve the same problem!
This time if i enable hardware vertex processing everything works fine; otherwise if there is software V P enabled i get more or less the same images of yours.

Can''t find where is the problem!

Share this post


Link to post
Share on other sites
Check the device caps of the card (g_direct3D->GetDeviceCaps()) and check the value of caps.MaxVertexIndex. You can only use 32 bit index buffers if this value is GREATER than 0xFFFF (65535). Most likely, this value is 65535 on the card you''re having problems with.

-Brett

Share this post


Link to post
Share on other sites
I had a problem with 32 bit index buffers... I am using a Geforce2. Changing to 16 bit fixed it.

All I gotta say is if you have more than 65535 vertices in a buffer, then just use another vertex buffer

Share this post


Link to post
Share on other sites
Yup. Only GeForce3/4 and Radeon8500 (possibly Matrox Parhelia) seem to support 32 bit index buffers properly. If you need more than that, you''re probably better off setting the base index to whatever you need and just use 0..65535 indices. That way, you don''t have to have as many vertex buffers.

- JQ
Full Speed Games. Coming soon.

Share this post


Link to post
Share on other sites