Jump to content
  • Advertisement
Sign in to follow this  
BlackJoker

How to keep D2D text when window resizing

This topic is 2116 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

When I resize window, I must also resize a swap chain. I done this, but I have also D2D text and it drawing incorrect when window size changed.

How to sync d2drendertarget size with d3drendertarget size and keep text size appropriate after window is resized?

Edited by BlackJoker

Share this post


Link to post
Share on other sites
Advertisement
Still no answer, so I might as well give some hint. I haven't used D2D a lot, but when starting with my D3D11 stuff I grabbed some code and adapted it (since I urgently needed text output). Looking at that wrapper: I don't think you can actually resize an existing render target. Just recreate everything anew with the proper dimensions. Works fine.

Hope that helps.

Share this post


Link to post
Share on other sites

This is my initialization function for D2D. But It does not work correctly if I resize window:

first of all my objects are disapper from screen when I make window lower (if I make it bigger, objects not disapper). This happens only of D2D is initialized;

secod - text still not adopted to fit the screen correctly and I dont know why;

bool D3D11::InitializeD2D11()
{
	options.debugLevel = D2D1_DEBUG_LEVEL_ERROR;
	D2D1CreateFactory(D2D1_FACTORY_TYPE_MULTI_THREADED, options, &d2dfactory);

	swapChain->GetBuffer(0, IID_PPV_ARGS(&dxgiBackbuffer));
	D2D1_RENDER_TARGET_PROPERTIES props = D2D1::RenderTargetProperties(
		D2D1_RENDER_TARGET_TYPE_HARDWARE,
		D2D1::PixelFormat(DXGI_FORMAT_UNKNOWN, D2D1_ALPHA_MODE_PREMULTIPLIED));
	d2dfactory->CreateDxgiSurfaceRenderTarget(dxgiBackbuffer, props, &d2dRenderTarget);

	dxgiBackbuffer->Release();
	dxgiBackbuffer = NULL;
	d2dfactory->Release();
	d2dfactory = NULL;

	DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(DWriteFactory), (IUnknown**)(&DWriteFactory));

	DWriteFactory->CreateTextFormat(
		L"Cambria",
		NULL,
		DWRITE_FONT_WEIGHT_NORMAL,
		DWRITE_FONT_STYLE_NORMAL,
		DWRITE_FONT_STRETCH_NORMAL,
		12,
		L"",
		&textFormat);

	DWriteFactory->CreateTextFormat(
		L"Cambria",
		NULL,
		DWRITE_FONT_WEIGHT_NORMAL,
		DWRITE_FONT_STYLE_NORMAL,
		DWRITE_FONT_STRETCH_NORMAL,
		12,
		L"",
		&textFormat2);


	textFormat->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_NEAR);
	textFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_LEADING);
	textFormat2->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_FAR);
	textFormat2->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_LEADING);
	d2dRenderTarget->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::White), &Brush);

	return true;
}

Share this post


Link to post
Share on other sites

If I reinitialize D2D when make window smaller, all rendered content is disappear from window except text. If I make window bigger, content will display, but aspect ratio will be incorrect. If I switch off D2D, rendered content display correctly if I resize it in both sides. 

Edited by BlackJoker

Share this post


Link to post
Share on other sites

I guess, I solve the problem. Before resizing swap chain I deinitialize D2D and after resizing complete, I initialize it again. Looks like everything works fine. 

Share this post


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

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!