Drawing text efficiency

Nikolas Fraser 60 Reputation points
2023-11-15T12:31:03.3866667+00:00

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.

Thanks.

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,688 questions
C++
C++
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,787 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Castorix31 86,316 Reputation points
    2023-11-15T12:58:03.36+00:00

    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!";
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.