• ### Announcements

#### Archived

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

# getting terrain to display

## Recommended Posts

Hi all, I''ve got a heightmapped terrain that I''m trying to get up and running quickly. I used the D3D AppWizard in VC++ to get some skeleton code, and take care of initialization and all that. Now my question: The skeleton code uses D3DXmesh to render a teapot, and the render() code is like this :

HRESULT CMyD3DApplication::Render()
{
// Clear the viewport

m_pd3dDevice->Clear( 0L, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,
0x000000ff, 1.0f, 0L );

// Begin the scene

if( SUCCEEDED( m_pd3dDevice->BeginScene() ) )
{
// TODO: render world

// Render the teapot mesh

m_pD3DXMesh->DrawSubset(0);

// Render stats and help text

RenderText();

// End the scene.

m_pd3dDevice->EndScene();
}

return S_OK;
}

So, I''m assuming the mesh switches streams, and then draws whatever is in its local VB, since there''s no VB initialization or stream switching higher up the call stack. Now, all I do is add a call m_dunceMap.draw() instead of the call to render the teapot. This function just swaps streams, and calls renderPrimitive:

void dunceMap::draw(){
//set the proper vertex buffer and shader

m_pd3dDevice->SetStreamSource( 0, m_pVB, sizeof(struct dunce_mapVertex) );
m_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, SQUAREMAPSIZE);
}

The verts are stuck in the buffer at initialization as follows:

if (FAILED ( m_pVB->Lock ( 0, size*SQUAREMAPSIZE*SQUAREMAPSIZE, &data, 0) ) )
return NULL;

curr = (mapVertex *)data;

for (int i=0; i < SQUAREMAPSIZE; i+=2){
for (int j; j < SQUAREMAPSIZE; j++){
curr->x = (i+1)*VERT_SPACING;
curr->y = j*VERT_SPACING;
curr->z = map[i+1][j];
curr->color = D3DCOLOR_ARGB (255, 255, 0, 0);
curr->x = i*VERT_SPACING;
curr->y = j*VERT_SPACING;
curr->z = map[i][j];
curr->color = D3DCOLOR_ARGB (255, 255, 0, 0);
}
}
m_pVB->Unlock();

The problem is that it doesn''t display. So, I''m curious as to whether i''m ordering my vertices properly, or if I''m not going about this the right way at all ( I know switching streams isn''t the best idea, but I''m just trying to get things up on screen). Maybe I''m missing a niggling init-type call in there somewhere. If the last thing you want to do is sort through my code, it''s cool, but any help would be greatly appreciated.

##### Share on other sites
quote:

If the last thing you want to do is sort through my code, it''s cool, but any help would be greatly appreciated.

Ok then here goes; One thing i noticed is that you are only writing to the very first vertex in the buffer:

curr->x; etc etc etc

should be something like:

curr[ i * width + j ]->x;

##### Share on other sites
ok, I fixed my increment problems. The main thing is, even when i just put a triangle in the buffer, it doesn''t get rendered. Do I need any additional setup calls (that go in the neighborhood of SetStream) to make this work right?

Thanks,
Matt