Drawing text efficiency

Nikolas Fraser 40 Reputation points

Hi, I'm working on learning Direct2D and having a bit of a tough time with all the different types of text in C++. I am able to draw text on the screen, but the way I'm doing it seems terribly inefficient. I'm hoping for a suggest on how to improve this, or maybe how to understand handling text better.


Example snippet:

	// take string and convert
	std::string inText = "Hi";
	std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
	std::wstring wText = converter.from_bytes(inText);
	const wchar_t* text = wText.c_str();

This lets me draw "Hi" on the screen (text), but 4 lines seems like too much just to set up a small word.

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,289 questions
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,327 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Castorix31 79,921 Reputation points

    Hi, I'm working on learning Direct2D

    With Direct2D, you must use DirectWrite

    (+ SDK samples : https://github.com/microsoft/Windows-classic-samples/tree/main/Samples/Win7Samples/multimedia/DirectWrite)

    with wchar_t* like in SimpleHelloWorld sample, initialized by

     const wchar_t* wszText_;
     wszText_ = L"Hello World using DirectWrite!";