Here is the render portion of my code:
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);
//Set texture coords
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;
//Set rhw factors
Vertex[0].rhw=1.0f;
Vertex[1].rhw=1.0f;
Vertex[2].rhw=1.0f;
Vertex[3].rhw=1.0f;
//Tell D3D we are rending the scene
D3DDevice->BeginScene();
//Set render state
D3DDevice->SetRenderState(D3DRENDERSTATE_FILLMODE,D3DFILL_SOLID);
//Set Texture
D3DDevice->SetTexture(0,SampleTexture->GetSurface());
//Set scroll amounts
int screen_x=offset_x;
int screen_y=offset_y;
//Set upper left corner tile to correct start in tile map
int tile_x=(screen_x>>6),tile_y=(screen_y>>6);
int start_tile_x=tile_x;
//Iterate through height of screen
while (screen_y<ScreenHeight)
{
//Iterate through width of screen; account for offset for scrolling
screen_x=-offset_x;
while (screen_x<ScreenWidth)
{
//Make a 2 tris at current screenx,screeny
//Quite simply, a quad
Vertex[0].dvSX=screen_x;
Vertex[0].dvSY=screen_y;
Vertex[1].dvSX=screen_x+64;
Vertex[1].dvSY=screen_y;
Vertex[2].dvSX=screen_x;
Vertex[2].dvSY=screen_y+64;
Vertex[3].dvSX=screen_x+64;
Vertex[3].dvSY=screen_y+64;
//Draw the quad as a trianglestrip
//Specify to Direct3D this is a D3DTLVERTEX
//No transformation performed by D3D
D3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP,
D3DFVF_TLVERTEX,
Vertex,
4,
0);
//Increment screen_x by width of tile
screen_x+=64;
//Increment position in tile map by one tile
tile_x++;
}
//Move down one row in tile map
tile_y++;
//Reset tile_x to left side of viewable tile map
tile_x=start_tile_x;
//Increment screen_y by height of one tile
screen_y+=64;
}
//Tell D3D we are done
D3DDevice->EndScene();
return(0);
}
The problem is that with my method, offset_x will often times be within the visible screen which cause the entire grid to be drawn from that point. This causes blank tiles at the edges of the screen.