Original Post
So ive been trying to load a grid. I can get my code to compile, but unfortunately i cant see my grid, and i dont think it exists. I think the problem is in my loading but am not sure. Here my code does anyone see any obvious problems? thanks a-lot for your time, fitfool
//the vertex format...
#define D3DFVF_CUSTOMVERTEX ( D3DFVF_XYZ | D3DFVF_TEX1 | D3DFVF_NORMAL )
struct CUSTOMVERTEX
{
float x, y, z;
D3DVECTOR NORMAL;
float u,v;
CUSTOMVERTEX( float TempX, float TempY, float TempZ, D3DVECTOR TempNormal, float TempU, float TempV )
{
x = TempX;
y = TempY;
z = TempZ;
NORMAL = TempNormal;
u = TempU;
v = TempV;
}
CUSTOMVERTEX(){ }
};
//LOADING ******* dont mind commented out stuff
void D3D_CUSTOMGRAPHICS::SetupGraphics( IDirect3DDevice9 *D3DDevice, int ScreenWidth, int ScreenHeight )
{
D3D_CUSTOMMATRIX pMatrix;
D3DDevice->SetRenderState( D3DRS_AMBIENT, RGB(255,255,255) );
D3DDevice->SetRenderState( D3DRS_LIGHTING, true );
D3DDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
D3DDevice->SetRenderState( D3DRS_ZENABLE, true );
D3DDevice->SetRenderState( D3DRS_AMBIENT, D3DCOLOR_XRGB(100, 100, 100) );
/*CUSTOMVERTEX Triangle[] =
{
{ -3.0f, 3.0f, -3.0f, 0, 0, -1, 0, 1, },
{ 3.0f, 3.0f, -3.0f, 0, 0, -1, 1, 1, },
{ -3.0f, -3.0f, -3.0f, 0, 0, -1, 0, 0, },
{ 3.0f, -3.0f, -3.0f, 0, 0, -1, 1, 0, },
{ -3.0f, 3.0f, 3.0f, 0, 0, 1, 0, 1, },
{ -3.0f, -3.0f, 3.0f, 0, 0, 1, 0, 0, },
{ 3.0f, 3.0f, 3.0f, 0, 0, 1, 1, 1, },
{ 3.0f, -3.0f, 3.0f, 0, 0, 1, 1, 0, },
{ -3.0f, 3.0f, 3.0f, 0, 1, 0, 0, 1, },
{ 3.0f, 3.0f, 3.0f, 0, 1, 0, 1, 1, },
{ -3.0f, 3.0f, -3.0f, 0, 1, 0, 0, 0, },
{ 3.0f, 3.0f, -3.0f, 0, 1, 0, 1, 0, },
{ -3.0f, -3.0f, 3.0f, 0, -1, 0, 0, 1, },
{ -3.0f, -3.0f, -3.0f, 0, -1, 0, 0, 0, },
{ 3.0f, -3.0f, 3.0f, 0, -1, 0, 1, 1, },
{ 3.0f, -3.0f, -3.0f, 0, -1, 0, 1, 0, },
{ 3.0f, 3.0f, -3.0f, 1, 0, 0, 1, 0, },
{ 3.0f, 3.0f, 3.0f, 1, 0, 0, 1, 1, },
{ 3.0f, -3.0f, -3.0f, 1, 0, 0, 0, 0, },
{ 3.0f, -3.0f, 3.0f, 1, 0, 0, 0, 1, },
{ -3.0f, 3.0f, -3.0f, -1, 0, 0, 1, 0, },
{ -3.0f, -3.0f, -3.0f, -1, 0, 0, 0, 0, },
{ -3.0f, 3.0f, 3.0f, -1, 0, 0, 1, 1, },
{ -3.0f, -3.0f, 3.0f, -1, 0, 0, 0, 1, },
};
D3DDevice->CreateVertexBuffer( 24 * sizeof(CUSTOMVERTEX),
0, D3DFVF_CUSTOMVERTEX,
D3DPOOL_MANAGED, &VertexBuffer_1, NULL );
CUSTOMVERTEX *pVertices;
VertexBuffer_1->Lock( 0, sizeof(Triangle), (void**)&pVertices, 0 );
memcpy( pVertices, Triangle, sizeof(Triangle) );
VertexBuffer_1->Unlock();*/
CUSTOMVERTEX *GridVertex = new CUSTOMVERTEX[10000];
int VertexCount = 0;
for( float X = 0.0f; X < 100.0f; X += 3.0f )
{
for( float Z = 0.0f; Z < 100.0f; Z += 3.0f )
{
GridVertex[VertexCount] = CUSTOMVERTEX( X, 3.0f, Z, D3DXVECTOR3(-1.0f, 0.0f, 0.0f), 1.0f, 0.0f );// = { X, 3.0f, Z, -1, 0, 0, 1, 0 };
VertexCount++;
GridVertex[VertexCount] = CUSTOMVERTEX( X, -3.0f, Z, D3DXVECTOR3(-1.0f, 0.0f, 0.0f), 0.0f, 0.0f );// = { X, -3.0f, Z, -1, 0, 0, 0, 0 };
VertexCount++;
GridVertex[VertexCount] = CUSTOMVERTEX( X, 3.0f, Z, D3DXVECTOR3(-1.0f, 0.0f, 0.0f), 1.0f, 1.0f );// = { X, 3.0f, Z, -1, 0, 0, 1, 1 };
VertexCount++;
GridVertex[VertexCount] = CUSTOMVERTEX( X, -3.0f, Z, D3DXVECTOR3(-1.0f, 0.0f, 0.0f), 0.0f, 1.0f );//= { X, -3.0f, Z, -1, 0, 0, 0, 1 };
VertexCount++;
}
}
D3DDevice->CreateVertexBuffer( 10000 * sizeof(CUSTOMVERTEX),
0, D3DFVF_CUSTOMVERTEX,
D3DPOOL_MANAGED, &VertexBuffer_1, NULL );
CUSTOMVERTEX *VertexPointer;
VertexBuffer_1->Lock( 0, sizeof(GridVertex), (void**)&VertexPointer, 0 );
memcpy( VertexPointer, GridVertex, sizeof(GridVertex) );
VertexBuffer_1->Unlock();
pMatrix.SetProjection( D3DDevice,
D3DXToRadian(45),
(FLOAT)ScreenHeight/ (FLOAT)ScreenWidth,
1.0f,
10000.0f );
if( FAILED( D3DXCreateTextureFromFile(D3DDevice,
L"Wood1.PNG",
&Texture_1) ) )
{
MessageBox(NULL, L"Could not Load Grid.JPG", L"ERROR", MB_OK );
PostQuitMessage( 0 );
}
delete [] GridVertex;
InitLights( D3DDevice );
}
//RENDERING *****************
void D3D_CUSTOMGRAPHICS::Render( IDirect3DDevice9 *D3DDevice )
{
static D3D_CUSTOMMATRIX tMatrix;
static D3D_CUSTOMCAMERA Camera;
D3DDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0 );
D3DDevice->Clear( 0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
D3DDevice->BeginScene();
D3DDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
Camera.Update( D3DDevice );
tMatrix.SetFinal();
D3DDevice->SetTransform( D3DTS_WORLD, &tMatrix.Total );
D3DDevice->SetTexture(0, Texture_1);
D3DDevice->SetStreamSource( 0, VertexBuffer_1, 0, sizeof(CUSTOMVERTEX) );
/*D3DDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );
D3DDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 4, 2 );
D3DDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 8, 2 );
D3DDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 12, 2 );
D3DDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 16, 2 );
D3DDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 20, 2 );
D3DDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 24, 1 );*/
//for( int VertexCounter = 0; VertexCounter < 10000; VertexCounter += 4 )
//{
// D3DDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, VertexCounter, 1 );
//}
D3DDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 10000 );
D3DDevice->EndScene();
D3DDevice->Present(NULL, NULL, NULL, NULL);
return;
}