:( Hi sorry for yet again turning up with a noob questioln but ive encountered another program problem im unable to solve... This time its part of my Terrain Class. It seems to load each value in from the .raw file nicely putting it into an array of CustomVertex and the indices into an array of ints. So i thought hey everything is loading correct why don't I render it? I was hoping some one could fish out the problem in my code.
[SOURCE]
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ)
typedef struct CVert
{
float x,y,z;
}CVert;
class CTerrain
{
public:
void Render (LPDIRECT3DDEVICE9 device);
D3DMATERIAL9 m_material;
void SetMaterial (void);
void FillBuffers (LPDIRECT3DDEVICE9 device);
void LoadRaw (int size, char *fName);
CTerrain();
virtual ~CTerrain();
int NumCells;
int NumVertz;
float step;
D3DXVECTOR3 MinBounds;
D3DXVECTOR3 MaxBounds;
CVert *verts;
int *inds;
LPDIRECT3DVERTEXBUFFER9 VrtBuffer;
LPDIRECT3DINDEXBUFFER9 IndBuffer;
};
[/SOURCE]
^^^^ was the Terrain Class header its got my Custom Vertex CVert and teh terrain define.
[SOURCE]
/////SECOND INIT FUNCTION FILLS BUFFERS WITH INDICES AND VERTICES
void CTerrain::FillBuffers(LPDIRECT3DDEVICE9 device)
{
void *pVertices;
int *pIndex;
device->CreateVertexBuffer(sizeof(CVert)*NumVertz,
D3DUSAGE_WRITEONLY,
D3DFVF_CUSTOMVERTEX,
D3DPOOL_MANAGED,
&VrtBuffer,
NULL);
VrtBuffer->Lock( 0, sizeof(verts), (void**)&pVertices, 0 );
memcpy( pVertices, verts, sizeof(verts) );
VrtBuffer->Unlock();
device->CreateIndexBuffer(sizeof(int)*(NumCells*NumCells*2)*3,
D3DUSAGE_WRITEONLY,
D3DFMT_INDEX16,
D3DPOOL_MANAGED,
&IndBuffer,
NULL);
IndBuffer->Lock(0,sizeof(inds),(void**)&pIndex,0);
memcpy( pIndex, inds, sizeof(inds) );
IndBuffer->Unlock();
}
////RENDER
void CTerrain::SetMaterial()
{
//this function is temporary just assigning the material some values
ZeroMemory( &m_material, sizeof(D3DMATERIAL9) );
m_material.Diffuse.r = m_material.Ambient.r = 255;
m_material.Diffuse.g = m_material.Ambient.g = 255;
m_material.Diffuse.b = m_material.Ambient.b = 255;
m_material.Diffuse.a = m_material.Ambient.a = 1.0f;
}
void CTerrain::Render(LPDIRECT3DDEVICE9 device)
{
// Set material
SetMaterial ();
device->SetMaterial( &m_material );
D3DXMATRIXA16 matWorld;
D3DXMatrixTranslation(&matWorld,0,0,0);
device->SetTransform( D3DTS_WORLD, &matWorld );
device->SetStreamSource( 0, VrtBuffer,0, sizeof(CVert) );
device->SetIndices(IndBuffer);
// draw a triangle list using our 24 vertices and 12 triangles
device->DrawIndexedPrimitive( D3DPT_TRIANGLELIST,0,0,24,0,12);
}
[/SOURCE]
^^Render function and fill buffers of CTerrain
[SOURCE]
//Projection Matrix Setting function fov is PI/4 aspect is 800/600 zn is 0 zf is 1000
void CProjection::Update(LPDIRECT3DDEVICE9 device)
{
D3DXMATRIX matProj;
D3DXMatrixPerspectiveFovLH( &matProj, fov, aspect,zn,zf );
device->SetTransform( D3DTS_PROJECTION, &matProj );
}
//Camera function its set up a little looking at 0,0,0
void CCamera::Update(LPDIRECT3DDEVICE9 device)
{
// Get D3DX to fill in the matrix values
D3DXMATRIXA16 matView;
D3DXMatrixLookAtLH( &matView, &this->vEyePt, &this->vLookatPt, &this->vUpVec );
// Set our view matrix
device->SetTransform( D3DTS_VIEW, &matView );
}
{/SOURCE]
Camera and Projection Matricies
[SOURCE]
void Render (void)
{
if( NULL == Core.device )
return;
// Begin the scene
if( SUCCEEDED( Core.device->BeginScene() ) )
{
// Rendering of scene objects can happen here
Terra.SetMaterial ();
Terra.Render (Core.device);
// Destroy the vertex buffer
// End the scene
Core.device->EndScene();
}
// Present the backbuffer contents to the display
Core.device->Present( NULL, NULL, NULL, NULL );
}
void GInit ( HWND hwnd)
{
Core.Init (hwnd);
Core.MainCam.Init (0,10,10,0,0,0);
Core.Projection.Init (800/600,0,1000);
Terra.LoadRaw (64,"Height.raw");
Terra.FillBuffers (Core.device);
Core.Projection.Update (Core.device);
Core.device->SetRenderState( D3DRS_AMBIENT, D3DCOLOR_XRGB(50,50,50) );
}
[/SOURCE]
//And there is my classes being used Core is just a D3D initer and holds the device.
but all this is giving me nothing...
what am i doing wrong