I am making a game in DirectX 8 for a retrocomputing game contest. I am creating a Real Time Strategy game, and I am trying to make a minimap, which is merely an orthographic view of the terrain. When I try to do this, though, I get black pixels:
Here is some of my code:
void TERRAIN::RenderLandscape()
{
//Set orthogonal rendering view & projection
SetOrthogonalView();
//Retrieve the surface of the back buffer
IDirect3DSurface8 *backSurface = NULL;
m_pDevice->GetRenderTarget(&backSurface);
//Get the surface of the minimap texture
IDirect3DSurface8 *landScapeSurface = NULL;
m_pLandScape->GetSurfaceLevel(0, &landScapeSurface);
//Set render target to the m_visible surface
m_pDevice->SetRenderTarget(landScapeSurface, backSurface);
//Clear render target to black
m_pDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0);
m_pDevice->BeginScene();
m_pDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 0);
//Set render states
m_pDevice->SetRenderState(D3DRS_LIGHTING, false);
m_pDevice->SetRenderState(D3DRS_ZWRITEENABLE, true);
//Alpha from alphaTextures, stage 0
m_pDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
m_pDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
//Color from textures, stage 1
m_pDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
m_pDevice->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
m_pDevice->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
m_pDevice->SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_CURRENT);
//Set blend states
m_pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
m_pDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
m_pDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
m_pDevice->SetMaterial(&m_mtrl);
//Draw mesh once for each terrain type
for (int i = 0; i < (int)m_diffuseMaps.size(); i++)
{
m_pDevice->SetTexture(0, m_alphaMaps[i]);
m_pDevice->SetTexture(1, m_diffuseMaps[i]);
for (int p = 0; p < (int)m_patches.size(); p++)
{
m_patches[p]->Render();
}
}
m_pDevice->EndScene();
//Reset render target to back buffer
m_pDevice->SetRenderTarget(0, backSurface);
//Release surfaces
landScapeSurface->Release();
backSurface->Release();
D3DXSaveTextureToFile("lscape.bmp", D3DXIFF_BMP, m_pLandScape, NULL);
}
I was able to create what I wanted the minimap to look like by calling the orthographic function that is shown earlier on in the function:
However, I only get a black image. What could I be doing wrong? I have searched around and none of the online help so far or the demos I have found are of any help.
Thanks,
-RJ