Skip to content

Commit defa629

Browse files
committed
GameObjectsDisplay: Center text, draw cube around objects
1 parent 5619822 commit defa629

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/mods/tools/GameObjectsDisplay.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,10 @@ void GameObjectsDisplay::on_frame() {
259259

260260
m_d3d12.effect->SetProjection(proj_directx);
261261
m_d3d12.effect->SetView(view_directx);
262+
m_d3d12.effect->SetTexture(m_d3d12.text_texture->get_srv_gpu(), m_d3d12.states->LinearWrap());
263+
264+
m_d3d12.effect_no_tex->SetProjection(proj_directx);
265+
m_d3d12.effect_no_tex->SetView(view_directx);
262266
});
263267
}
264268

@@ -304,7 +308,7 @@ void GameObjectsDisplay::on_frame() {
304308
DirectX::SimpleMath::Matrix world =
305309
DirectX::SimpleMath::Matrix{&world_matrix[0][0]};
306310

307-
d3d12_work.emplace_back([this, world, owner_name](const BackBufferRenderer::RenderWorkData& data) {
311+
d3d12_work.emplace_back([this, owner_name, world](const BackBufferRenderer::RenderWorkData& data) {
308312
// Create barrier to transition to render target
309313
D3D12_RESOURCE_BARRIER barrier{};
310314
barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
@@ -337,8 +341,9 @@ void GameObjectsDisplay::on_frame() {
337341
data.command_list->ClearRenderTargetView(m_d3d12.text_texture->get_rtv(), DirectX::Colors::Transparent, 0, nullptr);
338342

339343
m_d3d12.sprite_batch->Begin(data.command_list);
340-
341-
m_d3d12.font->DrawString(m_d3d12.sprite_batch.get(), owner_name.c_str(), DirectX::SimpleMath::Vector2(0, 0), DirectX::Colors::White);
344+
345+
const auto measurements = m_d3d12.font->MeasureString(owner_name.c_str());
346+
m_d3d12.font->DrawString(m_d3d12.sprite_batch.get(), owner_name.c_str(), DirectX::SimpleMath::Vector2(256.0f - glm::min(DirectX::XMVectorGetX(measurements) / 2.0f, 256.0f), 256.0f), DirectX::Colors::White);
342347

343348
m_d3d12.sprite_batch->End();
344349

@@ -359,6 +364,12 @@ void GameObjectsDisplay::on_frame() {
359364
D3D12_CPU_DESCRIPTOR_HANDLE bbrtv_heaps[] = { data.backbuffer_ctx->get_rtv() };
360365
data.command_list->OMSetRenderTargets(1, bbrtv_heaps, FALSE, nullptr);
361366

367+
if (m_effect_alpha > 0.0f) {
368+
m_d3d12.effect_no_tex->SetWorld(world);
369+
m_d3d12.effect_no_tex->Apply(data.command_list);
370+
m_d3d12.quad->Draw(data.command_list);
371+
}
372+
362373
m_d3d12.effect->SetWorld(world);
363374
m_d3d12.effect->Apply(data.command_list);
364375
m_d3d12.quad->Draw(data.command_list);

0 commit comments

Comments
 (0)