My code is failing inside of this function in the first DrawPrimitive call from what debugger tells me and waht my own personal debugging has been through.
void CTerrain::Draw()
{
g_pDevice->SetStreamSource(0,pTerrainVertexBuffer,sizeof(D3DVERTEX));
g_pDevice->DrawPrimitive(D3DPT_TRIANGLELIST,0,16129);
g_pDevice->DrawPrimitive(D3DPT_TRIANGLELIST,48387,16129);
}
I have no idea why it''s crashing though I kind of believe it could be dealing with my vertexbuffer code which is dealt with in this section.
void CTerrain::CreateVertexBuffer(void)
{
static D3DVERTEX aTerrain[(TERRAIN_X - 1) * (TERRAIN_Y - 1) * 6];
unsigned char aHeightMap[TERRAIN_X][TERRAIN_Y];
int VertexCount = 0;
ifstream File;
BYTE *pData;
File.open("heightmap.raw",ios::binary);
for(int j = 0; j < TERRAIN_Y; j++)
{
for(int i = 0; i < TERRAIN_X; i++)
{
File.get(aHeightMap[i][j]);
}
}
File.close();
for(int y = 0; y < TERRAIN_Y - 1; y++)
{
for(int x = 0; x < TERRAIN_X - 1; x++)
{
aTerrain[VertexCount].fX = (float)x;
aTerrain[VertexCount].fY = (float)y;
aTerrain[VertexCount].fZ = (float)aHeightMap[x][y] / 10;
aTerrain[VertexCount+ 1].fX = (float)x+1;
aTerrain[VertexCount+ 1].fY = (float)y;
aTerrain[VertexCount+ 1].fZ = (float)aHeightMap[x+1][y] / 10;
aTerrain[VertexCount+ 2].fX = (float)x+1;
aTerrain[VertexCount+ 2].fY = (float)y+1;
aTerrain[VertexCount+ 2].fZ = (float)aHeightMap[x+1][y+1] / 10;
aTerrain[VertexCount + 3].fX = (float)x;
aTerrain[VertexCount + 3].fY = (float)y;
aTerrain[VertexCount + 3].fZ = (float)aHeightMap[x][y] / 10;
aTerrain[VertexCount + 4].fX = (float)x + 1;
aTerrain[VertexCount + 4].fZ = (float)aHeightMap[x + 1][y + 1] / 10;
aTerrain[VertexCount + 4].fY = (float)y + 1;
aTerrain[VertexCount + 5].fX = (float)x;
aTerrain[VertexCount + 5].fY = (float)y + 1;
aTerrain[VertexCount + 5].fZ = (float)aHeightMap[x][y + 1] / 10;
VertexCount +=6;
}
}
g_pDevice->CreateVertexBuffer(sizeof(aTerrain)*VertexCount,NULL,
D3DFVF_CUSTOMVERTEX,
D3DPOOL_DEFAULT,
&pTerrainVertexBuffer);
if(FAILED(pTerrainVertexBuffer->Lock(0,sizeof(pData),(BYTE **)&pData,0)))
{
MessageBox(NULL,"Locked","Locked",MB_OK);
}
CopyMemory(pData,&aTerrain,sizeof(aTerrain));
pTerrainVertexBuffer->Unlock();
}
could any of you provide me some help to why my app isnt displaying and running when i have those 2 draw primitive calls runnin, when i comment them out the app runs fine??
Eric Wright o0Programmer0o