I've been working on a tiling engine in VC++ to learn DirectX and VC++ better, and so far i'm able to tile a single tile to the screen using a vertex buffer. What I can't figure out is how to render multiple. I've done it a while back in C#, but I can't find the code I used so i'm back to square one. The way I seem to remember doing it in C# was create one quad, and transform on each render to create new tiles. The only thing is I'm not sure how to go about that in C++.
Here is what i've got so far.
My vertex structure
struct CUSTOMVERTEX
{
float x, y, z; // Position in 3d space
DWORD color; // Color
float u, v; // Texture coordinates
};
I declare my vertex buffer, but when I try to create an array for doing it the non-transform method I get compile errors.
CUSTOMVERTEX g_vertices[] =
{
{-1.0f, 1.0f, -1.0f, D3DCOLOR_XRGB( 255, 255, 255 ), 0.0f, 0.0f},
{ 1.0f, 1.0f, -1.0f, D3DCOLOR_XRGB( 255, 255, 255 ), 1.0f, 0.0f},
{ 1.0f, -1.0f, -1.0f, D3DCOLOR_XRGB( 255, 255, 255 ), 1.0f, 1.0f},
{-1.0f, 1.0f, -1.0f, D3DCOLOR_XRGB( 255, 255, 255 ), 0.0f, 0.0f},
{ 1.0f, -1.0f, -1.0f, D3DCOLOR_XRGB( 255, 255, 255 ), 1.0f, 1.0f},
{-1.0f, -1.0f, -1.0f, D3DCOLOR_XRGB( 255, 255, 255 ), 0.0f, 1.0f},
};
void CGameApp::OnRenderFrame( LPDIRECT3DDEVICE9 pDevice, float elapsedTime )
{
pDevice->Clear( 0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB( 0, 0, 0 ), 1.0f, 0 );
pDevice->BeginScene();
pDevice->SetTransform( D3DTS_WORLD, m_transform.GetTransform() );
m_VB.Render( pDevice, 2, D3DPT_TRIANGLELIST );
pDevice->EndScene();
pDevice->Present( 0, 0, 0, 0 );
}
I thought if I could make an array and fill in the vertex buffer with all the individual coordinates and render them it would work fine, but I run into more issues that route. Also is it better to do tiling using the transform method, or the locking and unlocking with an array. I want to add in lighting and such next, but not sure if its possible with one method or both.
Thanks for your time,
Slyprid