OK here is my problem...I have terrain loaded from a heightmap (very cheesy) and then it does it stuff and renders...however, when i defined the indices clockwise and turned on counter clockwise culling...you see a half-drawn square (1 triangle) drawn in the incorrect order...however, when i changed the indices to counter-clockwise, with counter-clockwise culling still on, it drew all the polys correctly...i dont know if this is becuz of my vertex buffer or is D3D is screwing up...here is the code
Index Buffer
WORD a = 0;
WORD b = m_wRows + 2;
WORD c = b - 1;
WORD x, z, i = 0;
for(z = 0; z < m_wCols; z++)
{
for(x = 0; x < m_wRows; x++)
{
pIndices[i] = a;
pIndices[i + 1] = c; //REALLY STRANGE
pIndices[i + 2] = b; //FOR SOME REASON (IN THIS CODE SOMEWHERE)
pIndices[i + 3] = a; //WE MUST SET INDICES COUNTER CLOCKWISE
pIndices[i + 4] = b; //SO THEY ARE DRAWN CORRECTLY WHEN CULLING IS
pIndices[i + 5] = a+1; //SET TO COUNTERCLOCKWISE (SEE THE PROBLEM???)
a++;
b++;
c++;
i += 6;
}
a++;
b++;
c++;
}
And the vertex buffer (this is where i think the problem lies, i think it is somehow creating the vertices backwards thus reversing the indices order...however i cant see how it is doing this)
DWORD i = 0; //used to index pcvVertices
VOID* pVertices; //to lock vertex buffer
ENGINE_CUSTOM_VERTEX* pcvVertices = new ENGINE_CUSTOM_VERTEX[m_dwNumOfVertices]; //Array holds the veritces
WORD x = 0;
WORD z = 0;
//Centre terrain around the origin
float zStart = (0.0f - (m_wSize/2.0f));
float xStart = (0.0f - (m_wSize/2.0f));
//Setup vertices for terrain
for(z = 0; z < m_wSize; z += m_iStepSize)
{
for(x = 0; x < m_wSize; x += m_iStepSize)
{
pcvVertices[i].x = x + xStart;
pcvVertices[i].y = (float)m_HeightMap[x + (z * m_wSize)] / m_fHeightScale; //value from heightmap
pcvVertices[i].z = z + zStart;
pcvVertices[i].Diffuse = D3DCOLOR_XRGB(m_HeightMap[x + (z * m_wSize)], 0, 0); //color value from height value
pcvVertices[i].nx = 0.0;
pcvVertices[i].ny = 1.0;
pcvVertices[i].nz = 0.0;
i++;
}
}
any ideas appreciated