heres the code i use to generate/draw terrain:

That works fine for flat terrains, but when i added (rand() % 2) to the y value of each vertex, i get really messed up tiles (image attached).Code:void Create_cVertex(cVertex *p_Vertex, float fX, float fY, float fZ, float fTU, float fTV) { p_Vertex->x = fX; p_Vertex->y = fY; p_Vertex->z = fZ; p_Vertex->tu = fTU; p_Vertex->tv = fTV; p_Vertex->color = D3DCOLOR_XRGB(255, 255, 255); } #define TILES_X 64 #define TILES_Y 64 // Globals: cVertex terrain[TILES_X * TILES_Y][4]; IDirect3DTexture9 *texture; //already loaded elsewhere void GenerateTerrain() { memset(&terrain, 0, sizeof(terrain)); unsigned int x, y; float SIZEX = 0.5f, SIZEY = 0.5f; srand(timeGetTime()); for (x = 0; x < TILES_X; ++x) { for (y = 0; y < TILES_Y; ++y) { Create_cVertex(&terrain[y + (x * TILES_Y)][0], SIZEX * y, rand() % 2, SIZEY - SIZEX, 0, 0); Create_cVertex(&terrain[y + (x * TILES_Y)][1], SIZEX * y, rand() % 2, SIZEY, 1, 0); Create_cVertex(&terrain[y + (x * TILES_Y)][2], SIZEX * (y + 1), rand() % 2, SIZEY - SIZEX, 0, 1); Create_cVertex(&terrain[y + (x * TILES_Y)][3], SIZEX * (y + 1), rand() % 2, SIZEY, 1, 1); } SIZEY += 0.5f; } } void DrawTerrain() { unsigned int x, y; for (x = 0; x < TILES_ROW; ++x) { for (y = 0; y < TILES_COLUMN; ++y) { g_Device->SetTexture(0, texture); g_Device->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, terrain[y + (x * TILES_Y)], sizeof(cVertex)); } } }

Also, ive been looking through a few sites, and ive noticed that this person did it differently, using only 3 vertices for each tile and his results seem fine, but its in OpenGL and he uses X and Z instead of X and Y.. Is his method better? and if so, how can i convert his code to work with DirectX.

Thanks in advance.