Code:
int TileEngine::Render(int offset_x,int offset_y)
{
D3DTLVERTEX Vertex[4];
Vertex[0].color=D3DRGB(1.0f,1.0f,1.0f);
Vertex[1].color=D3DRGB(1.0f,1.0f,1.0f);
Vertex[2].color=D3DRGB(1.0f,1.0f,1.0f);
Vertex[3].color=D3DRGB(1.0f,1.0f,1.0f);
Vertex[0].tu = 0.0f;
Vertex[0].tv = 0.0f;
Vertex[1].tu = 1.0f;
Vertex[1].tv = 0.0f;
Vertex[2].tu = 0.0f;
Vertex[2].tv = 1.0f;
Vertex[3].tu = 1.0f;
Vertex[3].tv = 1.0f;
Vertex[0].rhw=1.0f;
Vertex[1].rhw=1.0f;
Vertex[2].rhw=1.0f;
Vertex[3].rhw=1.0f;
SampleTexture=new TileTexture();
SampleTexture->LoadTexture("grass.bmp",D3DDevice,Direct_draw);
D3DDevice->SetTexture(0,SampleTexture->Surface);
D3DDevice->BeginScene();
D3DDevice->SetRenderState(D3DRENDERSTATE_FILLMODE,D3DFILL_SOLID);
int screen_x=-128,screen_y=-64;
int tile_x=0,tile_y=0;
while (screen_y<ScreenHeight)
{
screen_x=-64;
while (screen_x<ScreenWidth)
{
Vertex[0].dvSX=screen_x+offset_x;
Vertex[0].dvSY=screen_y+offset_y;
Vertex[1].dvSX=screen_x+64+offset_x;
Vertex[1].dvSY=screen_y+offset_y;
Vertex[2].dvSX=screen_x+offset_x;
Vertex[2].dvSY=screen_y+64+offset_y;
Vertex[3].dvSX=screen_x+64+offset_x;
Vertex[3].dvSY=screen_y+64+offset_y;
D3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP,
D3DFVF_TLVERTEX,
Vertex,
4,
0);
screen_x+=64;
tile_x++;
}
tile_y++;
tile_x=0;
screen_y+=64;
}
D3DDevice->EndScene();
return(0);
}
This sample clips fine for me...just need to set textures according to tile and actually use some tile map logic to get the map to display correctly.