Archived

This topic is now archived and is closed to further replies.

kapru

y wont this work

Recommended Posts

Im expementing the different ways of doing a terrain my first way worked but in my second way nothing is being displayed its probably a stuip little mistake but i seam to take years to find them heres the landscape code int CLandScape::InitTerrain(char *filename,int size) { MapSize=size; //load the height map into an array LoadHeightMap(filename,size); //Setup the rendering patches //PatchX=size/PATCHSIZE; //PatchY=size/PATCHSIZE; //init the patch array //Patch = new TPatch[PatchX*PatchY]; //int pos,hmx,hmy,pn; //for(int i=0;iCreateVertexBuffer(65535*sizeof(vertex),D3DUSAGE_WRITEONLY,D3DFVF_VERTEX,D3DPOOL_DEFAULT, &TerrVB); d3dDevice->CreateIndexBuffer(65535*sizeof(short),D3DUSAGE_WRITEONLY,D3DFMT_INDEX16,D3DPOOL_DEFAULT, &TerrIB); D3DXCreateTextureFromFile(d3dDevice, "tex1.bmp", &tex); return true; } int CLandScape::LoadHeightMap(char *filename,int size) { FILE *pFile = NULL; pFile = fopen( filename, "rb" ); if ( pFile == NULL ) { MessageBox(NULL, "Can''t Find The Height Map!", "Error", MB_OK); return false; } HeightMap = new BYTE[size*size]; fread(HeightMap , 1, size*size, pFile ); int result = ferror( pFile ); if (result) { MessageBox(NULL, "Failed To Get Data!", "Error", MB_OK); fclose(pFile); return false; } fclose(pFile); return true; } int CLandScape::GetHeight(int X, int Y) { int x = X % MapSize; int y = Y % MapSize; return HeightMap[x + (y * MapSize)]; } int CLandScape::RenderLandScape() { //Create the vertex buffer //not gonna use patch yet vertex* v; int CurrVertex=0; vertex vert; TerrVB->Lock(0, 65535*sizeof(vertex), (BYTE**)&v, 0); //generate the vertexs on the fly for(int j=0;jUnlock(); //generate the index buffer unsigned short *ind; TerrIB->Lock(0, 65535*sizeof(short), (BYTE**)&ind, D3DLOCK_DISCARD ); NumIndices=0; for(j=0;jUnlock(); D3DXMATRIX temp; D3DXMatrixIdentity(&temp); d3dDevice->SetTransform(D3DTS_WORLD, &temp); //now lets render it d3dDevice->SetRenderState( D3DRS_FILLMODE, D3DFILL_SOLID ); d3dDevice->SetStreamSource(0, TerrVB, sizeof(vertex)); d3dDevice->SetTexture(0, tex); d3dDevice->SetVertexShader(D3DFVF_VERTEX); d3dDevice->SetIndices(TerrIB, 0); d3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0,NumVertices, 0,(NumIndices) / 3); return true; } enjoy

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Just try not copy/paste code and understand it.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Could not have said it better than AP.

Share this post


Link to post
Share on other sites
i do understand it i have already made a landscape engine but it was limited to a certain size and it was all completely my own work. This was just a quick hack fron nehe''s demo while im at work trying out an idea to see what sort of speed rebuilding the vertex and index buffers every frame

Share this post


Link to post
Share on other sites