Jump to content
  • Advertisement
Sign in to follow this  
Jannes

Render to view and dialog control

This topic is 4666 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello For my mapeditor (MFC - MDI App/DirectX9) i would like to render the map to the main view and selectable objects to a static control in a modeless dialog using swap chains. However it doesnt work, plz see the snippets below. Initialization of D3D/Device and rendering to the view:
if( NULL == ( p_D3D = Direct3DCreate9( D3D_SDK_VERSION ) ) || !D3DXCheckVersion(D3D_SDK_VERSION, D3DX_SDK_VERSION))
    return false;

ZeroMemory( &d3d_pp, sizeof(D3DPRESENT_PARAMETERS) );
d3d_pp.Windowed = Windowed;
d3d_pp.BackBufferCount = 1;
// z-Buffer:
d3d_pp.EnableAutoDepthStencil = TRUE;
d3d_pp.AutoDepthStencilFormat = D3DFMT_D16; //16-Bit

D3DDISPLAYMODE displ_mode;
p_D3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &displ_mode);
ScreenResolutionWidth = displ_mode.Width;
ScreenResolutionHeight = displ_mode.Height;
//d3d_pp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3d_pp.SwapEffect = D3DSWAPEFFECT_COPY;
d3d_pp.PresentationInterval = D3DPRESENT_INTERVAL_ONE; //Surface Flipping
d3d_pp.BackBufferFormat = displ_mode.Format;

ViewportWidth = ScreenResolutionWidth;
ViewportHeight = ScreenResolutionHeight;

p_D3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,window_hwnd,D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3d_pp, &gGfxDevice)

SetStates(); //Render/Samplerstates
SetProjection();


Initialization of rendering to the static control:
CSwapChain::CSwapChain(HWND render_target)
{ //HWND is hwnd of static control
	LPDIRECT3D9 p_D3D;
	gGfxDevice->GetDirect3D(&p_D3D);
	D3DPRESENT_PARAMETERS d3dpp;

	ZeroMemory(&d3dpp,sizeof(d3dpp));
	d3dpp.Windowed = true;
	d3dpp.SwapEffect = D3DSWAPEFFECT_COPY;
	//Benutze den vorhandenen Displaymodus:
	D3DDISPLAYMODE mode;
	p_D3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &mode);
	d3dpp.BackBufferFormat = mode.Format;
	d3dpp.hDeviceWindow = render_target;
	gGfxDevice->CreateAdditionalSwapChain(&d3dpp,&m_pSwapChain);
	hwnd = render_target;
}


Rendering:
CSwapChain::Render()
{
LPDIRECT3DSURFACE9 pBackBuffer = NULL;
//MainSwapChain is the device initial created swapchain
MainSwapChain->GetBackBuffer( 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer );
gGfxDevice->SetRenderTarget( 0, pBackBuffer );
	
gGfxDevice->Clear( 0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,0), 1.0f, 0 );
    
gGfxDevice->BeginScene();
//do rendering to view	
gGfxDevice->EndScene();

MainSwapChain->Present( NULL, NULL, main_wnd_hwnd, NULL,0 );
	
//start rendering in static control (see following snippet)
}


CSwapChain::Render()
{
LPDIRECT3DSURFACE9 pBack = NULL;
m_pSwapChain->GetBackBuffer(0,D3DBACKBUFFER_TYPE_MONO,&pBack);
gGfxDevice->SetRenderTarget(0,pBack);

gGfxDevice->Clear( 0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,0), 1.0f, 0 );
 
//Render:
if(SUCCEEDED(gGfxDevice->BeginScene())){
		gGfxDevice->EndScene();
}
	
m_pSwapChain->Present(NULL,NULL,hwnd,NULL,0);

pBack->Release();
}


Thanks for any help

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!