One problem that I see is that you return false from IT_Terrain::LoadTerrain if you fail to open the file. This may be fine but look what you are doing right before that; do you see! You are allocating memory for the heightmap and not deleting it before you exit. I don't see where you delete it at all until you reach the end of you procedure. Memory leak!
How you are creating and calculating you're indices may be a problem too. You allocare ( iSize - 1 ) * ( iSize - 1 ) * 6, but that is not what you are looping through. When you are looping you doing that iSize - 1 thing again, why? Itsn't iSize the size as in wdth & height are the same, sizeo f the terrain? You may want to double check how you are creating the index buffer.
Now, if you rendering function I don't see how you are setting up you're projection matrices. Just world won't do! Well, at least id never did for me in anyn of my cases.
This is what I use:
// ---------------------------------------------------------------------------- //// Name : D3DSetupEnvironment ( )// Desc : Sets Direct3D environment variables & rendering states// ---------------------------------------------------------------------------- //HRESULT __stdcall D3DSetupEnvironment( void ){ D3DXMATRIX xWorld, xView, xProj ; D3DXFONT_DESC D3Dfd ; HDC hDC ; HRESULT hRet ; D3DXMatrixIdentity( &xWorld ) ; g_lpD3DDevice->SetTransform( D3DTS_WORLD, &( D3DMATRIX )xWorld ) ; D3DXMatrixLookAtLH( &xView, &D3DXVECTOR3( 0.0F, 0.0F, 0.0F ), &D3DXVECTOR3( 0.0F, 0.0F, 1.0F ), &D3DXVECTOR3( 0.0F, 1.0F, 0.0F ) ) ; g_lpD3DDevice->SetTransform( D3DTS_VIEW, &( D3DMATRIX )xView ) ; D3DXMatrixPerspectiveFovLH( &xProj, ( D3DX_PI / 4 ), 1.33333333F, 1.0F, 1000.0F ) ; g_lpD3DDevice->SetTransform( D3DTS_PROJECTION, &( D3DMATRIX )xProj ) ; g_lpD3DDevice->SetRenderState( D3DRS_LIGHTING, FALSE ) ; g_lpD3DDevice->SetRenderState( D3DRS_ZENABLE, TRUE ) ; hDC = GetDC( g_hWnd ) ; memset( &D3Dfd, 0, sizeof( D3DXFONT_DESC ) ) ; D3Dfd.Height = ( -MulDiv( 12, GetDeviceCaps( hDC, LOGPIXELSY ), 72 ) ) ; D3Dfd.Weight = FW_NORMAL ; D3Dfd.CharSet = ANSI_CHARSET ; D3Dfd.OutputPrecision = OUT_DEFAULT_PRECIS ; D3Dfd.PitchAndFamily = FIXED_PITCH | FF_MODERN ; D3Dfd.Quality = PROOF_QUALITY ; strcpy( D3Dfd.FaceName, "Comic Sans MS" ) ; ReleaseDC( g_hWnd, hDC ) ; if ( FAILED( hRet = D3DXCreateFontIndirect( g_lpD3DDevice, &D3Dfd, &g_lpD3DXFont ) ) ) { return ( hRet ) ; } // ... return ( D3D_OK ) ;}
Okay, now besides all this crap, this is the around about way you should be setting up you matrices...
D3DXMatrixIdentity( &xWorld ) ;
g_lpD3DDevice->SetTransform( D3DTS_WORLD, &( D3DMATRIX )xWorld ) ;
D3DXMatrixLookAtLH( &xView, &D3DXVECTOR3( 0.0F, 0.0F, 0.0F ),
&D3DXVECTOR3( 0.0F, 0.0F, 1.0F ),
&D3DXVECTOR3( 0.0F, 1.0F, 0.0F ) ) ;
g_lpD3DDevice->SetTransform( D3DTS_VIEW, &( D3DMATRIX )xView ) ;
D3DXMatrixPerspectiveFovLH( &xProj, ( D3DX_PI / 4 ), 1.33F, 1.0F, 1000.0F ) ;
g_lpD3DDevice->SetTransform( D3DTS_PROJECTION, &( D3DMATRIX )xProj ) ;
Notice that I setup up all three world, view and projection? You are only setting up world, so Direct3D may be wondering how to render you're heightmap.
Also, are you using depth buffering? I didn't see any states that altered it, but how you represent you geometry (i.e. the order of vertices) is important. I only state this fact to try and help you, if you already knew this please ingore what I just said. Well, depth buffering may give you some weird looking terrain that you can see through it it's not setup correctly.
I use this:
// ---------------------------------------------------------------------------- //// Name : D3DInitialize( )// Desc : Initializes Direct3D subsystem// ---------------------------------------------------------------------------- //HRESULT __stdcall D3DInitialize( void ){ D3DPRESENT_PARAMETERS D3Dpp ; HRESULT hRet ; if ( NULL == ( g_lpD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) ) { return ( E_FAIL ) ; } memset( &D3Dpp, 0, sizeof( D3DPRESENT_PARAMETERS ) ) ; D3Dpp.AutoDepthStencilFormat = D3DFMT_D16 ; D3Dpp.EnableAutoDepthStencil = TRUE ; D3Dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE ; D3Dpp.BackBufferWidth = 640 ; D3Dpp.BackBufferHeight = 480 ; D3Dpp.BackBufferFormat = D3DFMT_UNKNOWN ; D3Dpp.SwapEffect = D3DSWAPEFFECT_DISCARD ; D3Dpp.Windowed = TRUE ; if ( FAILED( hRet = g_lpD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &D3Dpp, &g_lpD3DDevice ) ) ) { return ( hRet ) ; } if ( FAILED( hRet = D3DSetupEnvironment( ) ) ) { return ( hRet ) ; } return ( D3D_OK ) ;
The display parameters are set up to use depth buffering. These two->
D3Dpp.AutoDepthStencilFormat = D3DFMT_D16 ;
D3Dpp.EnableAutoDepthStencil = TRUE ;
Also, I enable it with
g_lpD3DDevice->SetRenderState( D3DRS_ZENABLE, TRUE ) ;
I said before that the order of vertices are important, that is because Direct3D will cull(clip or and nnot render) them if you specify them in a certain order clock-wise(CW) or counter clock-wise(CCW). By default Direct3D culls CCW geometry. You can turn culling off too! So try that and see if you can see you're highmap.
Hope this helps.