Text |
As there is not support for text in DirectX, here are some options that can be used to draw text
Como no hay soporte para texto en DirectX, aquí están algunas opciones que pueden usarse para dibujar texto
|
Problem 1 |
Create a DirectX application called ClockX to draw text in DirectX. After creating the application, add a DirectX scene called MainScene. Cree una aplicación de DirectX llamada ClockX para dibujar texto en DirectX. Después de crear la aplicación, agregue una escena de DirectX llamada MainScene. |
MainScene.h |
//____________________________________________________________ MainScene.h #pragma once class MainScene : public DX11::Scene { public: DX11::Label label; DX11::Font font; void OnCreateScene(DX11::Engine& engine); . . . }; |
MainScene.cpp |
. . . void MainScene::OnCreateScene(DX11::Engine& engine) { //______________________________ 1. Set back color RGBA this->SetBackColor(0.0f, 0.0f, 0.4f, 1.0f); //______________________________ 2. Add children this->AddChild(label); //______________________________ 3. Camera & Light setup (light.ambientColor) camera.position.x = 0.0f; camera.position.y = 0.0f; camera.position.z = -5.0f; camera.lookAt.x = 0.0f; camera.lookAt.y = 0.0f; camera.lookAt.z = 1.0f; } void MainScene::OnUpdate(DX11::Engine& engine, float sec, float deltaSec) { Sys::Time time; wchar_t text[64]; _snwprintf_s(text, 64, _TRUNCATE, L"%02d:%02d:%02d", time.wHour, time.wMinute, time.wSecond); const int textWidth = font.GetTextWidth(text); const int textHeight = font.GetTextMetricsHeight(); const float x = (engine.GetScreenWidth() - textWidth)/2.0f; const float y = (engine.GetScreenHeight() - textHeight)/2.0f; label.Set(engine, font, x, y, text); camera.Update(); } . . . |
ClockX.h |
#pragma once //______________________________________ ClockX.h #include "Resource.h" #include "MainScene.h" class ClockX : public DX11::Window { public: MainScene mainScene; }; |
ClockX.cpp |
. . . int APIENTRY wWinMain(. . .) { ClockX app; //_________________________________________________________ 1. Create font app.mainScene.font.CreateData(L"Arial", 60, RGB(0, 0, 0), RGB(0, 255, 0)); app.engine.AddChild(app.mainScene.font); //_________________________________________________________ 2. Add vertex buffers to the engine app.engine.AddChild(app.mainScene.label); //_________________________________________________________ 3. Set vertex buffers to the 3D objects //_________________________________________________________ 4. Scene setup app.engine.scene[L"mainScene"] = &app.mainScene; app.engine.SetCurrentScene(L"mainScene"); //_________________________________________________________ 5. Run the app return app.Run(. . .); } |