Original Post
Hey everybody, I was wondering if you could help me figure out an algorithm to fill a vertexbuffer with transformed vertices, forming a grid. I have a few specifications: I want each grid square to be equilateral I want the grid to be CxR big I want each square to consist of 2 tris I think I have part of it, but I can't get the code to work: But that doesn't seem to work for me. Am I doing something wrong, or is some other part of my code messed up (I'm not getting any errors, it just doesn't render)? (Note: It might help if I put them as two tris and not a quad, huh?) My other stuff renders just fine I think part of my problem is that I'm trying to make the vertex array into a grid, when I should just make each one in order. Thanks!
for(int iRow = 0; iRow < iMaxRows; iRow+=2)
{
for(int iCol = 0; iCol < iMaxCols; iCol+=2)
{
int iSector = iRow * iMaxCols + iCol;
Vertices[iSector].x = iCol * iTileSize;
Vertices[iSector].y = iRow * iTileSize;
Vertices[iSector].z = 0.0f;
Vertices[iSector].diffuse = D3DCOLOR_XRGB(255, 255, 255);
Vertices[iSector].u = 0.0f;
Vertices[iSector].v = 0.0f;
iSector = iRow * iMaxCols + (iCol + 1);
Vertices[iSector].x = (iCol+1) * iTileSize;
Vertices[iSector].y = iRow * iTileSize;
Vertices[iSector].z = 0.0f;
Vertices[iSector].diffuse = D3DCOLOR_XRGB(255, 255, 255);
Vertices[iSector].u = 1.0f;
Vertices[iSector].v = 0.0f;
iSector = (iRow + 1) * iMaxCols + iCol;
Vertices[iSector].x = iCol * iTileSize;
Vertices[iSector].y = (iRow+1) * iTileSize;
Vertices[iSector].z = 0.0f;
Vertices[iSector].diffuse = D3DCOLOR_XRGB(255, 255, 255);
Vertices[iSector].u = 0.0f;
Vertices[iSector].v = 1.0f;
iSector = (iRow + 1) * iMaxCols + (iCol + 1);
Vertices[iSector].x = (iCol+1) * iTileSize;
Vertices[iSector].y = (iRow+1) * iTileSize;
Vertices[iSector].z = 0.0f;
Vertices[iSector].diffuse = D3DCOLOR_XRGB(255, 255, 255);
Vertices[iSector].u = 1.0f;
Vertices[iSector].v = 1.0f;
}
}