Recast: properly render text over screen

Use the drawlist wrapper instead of relying on ImGui windows (which didn't work to begin with). Also fixed all text colors that weren't converted from the previous library.
This commit is contained in:
Kawe Mazidjatari 2024-07-09 16:37:38 +02:00
parent f964db2ccf
commit f843c69672
9 changed files with 66 additions and 75 deletions

View File

@ -290,20 +290,17 @@ void ConvexVolumeTool::handleRender()
dd.end();
}
void ConvexVolumeTool::handleRenderOverlay(double* /*proj*/, double* /*model*/, int* view)
void ConvexVolumeTool::handleRenderOverlay(double* /*proj*/, double* /*model*/, int* /*view*/)
{
// Tool help
const int h = view[3];
if (!m_npts)
{
ImGui::SetCursorPos(ImVec2(280, (float)h-40));
ImGui::TextColored(ImVec4(255,255,255,192), "LMB: Create new shape. SHIFT+LMB: Delete existing shape (click inside a shape).");
ImGui_RenderText(ImGuiTextAlign_e::kAlignLeft,
ImVec2(280, 40), ImVec4(1.0f,1.0f,1.0f,0.75f), "LMB: Create new shape. SHIFT+LMB: Delete existing shape (click inside a shape).");
}
else
{
ImGui::SetCursorPos(ImVec2(280, (float)h-40));
ImGui::TextColored(ImVec4(255,255,255,192), "Click LMB to add new points. Click on the red point to finish the shape.");
ImGui::SetCursorPos(ImVec2(280, (float)h-60));
ImGui::TextColored(ImVec4(255,255,255,192), "The shape will be convex hull of all added points.");
ImGui_RenderText(ImGuiTextAlign_e::kAlignLeft,
ImVec2(280, 60), ImVec4(1.0f,1.0f,1.0f,0.75f), "The shape will be convex hull of all added points.");
}
}

View File

@ -513,13 +513,14 @@ namespace ImPlot
void CrowdToolState::handleRenderOverlay(double* proj, double* model, int* view)
{
GLdouble x, y, z;
const int windowHeight = view[3];
// Draw start and end point labels
if (m_targetRef && gluProject((GLdouble)m_targetPos[0], (GLdouble)m_targetPos[1], (GLdouble)m_targetPos[2],
model, proj, view, &x, &y, &z))
{
ImGui::SetCursorPos(ImVec2((float)x, (float)y+25));
ImGui::TextColored(ImVec4(0,0,0,220), "TARGET"); // IMGUI_ALIGN_CENTER
ImGui_RenderText(ImGuiTextAlign_e::kAlignCenter,
ImVec2((float)x, windowHeight-((float)y+25)), ImVec4(0,0,0,0.8f), "TARGET");
}
@ -544,9 +545,8 @@ void CrowdToolState::handleRenderOverlay(double* proj, double* model, int* view)
model, proj, view, &x, &y, &z))
{
const float heuristic = node->total;// - node->cost;
ImGui::SetCursorPos(ImVec2((float)x, (float)y+25));
ImGui::TextColored(ImVec4(0,0,0,220), "%.2f", heuristic);
ImGui_RenderText(ImGuiTextAlign_e::kAlignCenter,
ImVec2((float)x, windowHeight-((float)y+25)), ImVec4(0,0,0,0.8f), "%.2f", heuristic);
}
}
}
@ -573,10 +573,10 @@ void CrowdToolState::handleRenderOverlay(double* proj, double* model, int* view)
? "none"
: g_traverseAnimTypeNames[animType];
ImGui::SetCursorPos(ImVec2((float)x, (float)y+15));
ImGui::TextColored(ImVec4(0,0,0,220), "%s (%d)", animTypeName, i);
ImGui_RenderText(ImGuiTextAlign_e::kAlignCenter,
ImVec2((float)x, windowHeight-((float)y+15)), ImVec4(0,0,0,0.8f), "%s (%d)", animTypeName, i);
}
}
}
}
}
if (m_agentDebug.idx != -1)
@ -602,8 +602,8 @@ void CrowdToolState::handleRenderOverlay(double* proj, double* model, int* view)
if (gluProject((GLdouble)nei->npos[0], (GLdouble)nei->npos[1], (GLdouble)nei->npos[2]+radius,
model, proj, view, &x, &y, &z))
{
ImGui::SetCursorPos(ImVec2((float)x, (float)y+15));
ImGui::TextColored(ImVec4(255,255,255,220), "%.3f", ag->neis[j].dist);
ImGui_RenderText(ImGuiTextAlign_e::kAlignCenter,
ImVec2((float)x, windowHeight-((float)y+15)), ImVec4(1.0f,1.0f,1.0f,0.8f), "%.3f", ag->neis[j].dist);
}
}
}
@ -1130,44 +1130,44 @@ void CrowdTool::handleRenderOverlay(double* proj, double* model, int* view)
{
rcIgnoreUnused(model);
rcIgnoreUnused(proj);
rcIgnoreUnused(view);
// Tool help
const int h = view[3];
float ty = (float)h-40;
float ty = 40;
if (m_mode == TOOLMODE_CREATE)
{
ImGui::SetCursorPos(ImVec2(280, ty));
ImGui::TextColored(ImVec4(255,255,255,192), "LMB: add agent. Shift+LMB: remove agent.");
ImGui_RenderText(ImGuiTextAlign_e::kAlignLeft,
ImVec2(280, ty), ImVec4(1.0f,1.0f,1.0f,0.75f), "LMB: add agent. Shift+LMB: remove agent.");
}
else if (m_mode == TOOLMODE_MOVE_TARGET)
{
ImGui::SetCursorPos(ImVec2(280, ty));
ImGui::TextColored(ImVec4(255,255,255,192), "LMB: set move target. Shift+LMB: adjust set velocity.");
ImGui_RenderText(ImGuiTextAlign_e::kAlignLeft,
ImVec2(280, ty), ImVec4(1.0f,1.0f,1.0f,0.75f), "LMB: set move target. Shift+LMB: adjust set velocity.");
ty -= 20;
ImGui::SetCursorPos(ImVec2(280, ty));
ImGui::TextColored(ImVec4(255,255,255,192), "Setting velocity will move the agents without pathfinder.");
ty += 20;
ImGui_RenderText(ImGuiTextAlign_e::kAlignLeft,
ImVec2(280, ty), ImVec4(1.0f,1.0f,1.0f,0.75f), "Setting velocity will move the agents without pathfinder.");
}
else if (m_mode == TOOLMODE_SELECT)
{
ImGui::SetCursorPos(ImVec2(280, ty));
ImGui::TextColored(ImVec4(255,255,255,192), "LMB: select agent.");
ImGui_RenderText(ImGuiTextAlign_e::kAlignLeft,
ImVec2(280, ty), ImVec4(1.0f,1.0f,1.0f,0.75f), "LMB: select agent.");
}
ty -= 20.f;
ImGui::SetCursorPos(ImVec2(280, ty));
ImGui::TextColored(ImVec4(255,255,255,192), "SPACE: Run/Pause simulation. 1: Step simulation.");
ty += 20.f;
ImGui_RenderText(ImGuiTextAlign_e::kAlignLeft,
ImVec2(280, ty), ImVec4(1.0f,1.0f,1.0f,0.75f), "SPACE: Run/Pause simulation. 1: Step simulation.");
ty -= 20.f;
ty += 20.f;
if (m_state && m_state->isRunning())
{
ImGui::SetCursorPos(ImVec2(280, ty));
ImGui::TextColored(ImVec4(255,32,16,255), "- RUNNING -");
ImGui_RenderText(ImGuiTextAlign_e::kAlignLeft,
ImVec2(280, ty), ImVec4(0.15f,1.0f,0.05f,0.8f), "- RUNNING -");
}
else
{
ImGui::SetCursorPos(ImVec2(280, ty));
ImGui::TextColored(ImVec4(255,255,255,128), "- PAUSED -");
ImGui_RenderText(ImGuiTextAlign_e::kAlignLeft,
ImVec2(280, ty), ImVec4(1.0f,0.15f,0.05f,0.8f), "- PAUSED -");
}
}

View File

@ -145,21 +145,19 @@ public:
virtual void handleRenderOverlay(double* proj, double* model, int* view)
{
GLdouble x, y, z;
const int h = view[3];
if (m_hitPosSet && gluProject((GLdouble)m_hitPos[0], (GLdouble)m_hitPos[1], (GLdouble)m_hitPos[2],
model, proj, view, &x, &y, &z))
{
int tx=0, ty=0;
m_editor->getTilePos(m_hitPos, tx, ty);
ImGui::SetCursorPos(ImVec2((float)x, (float)y-25));
ImGui::TextColored(ImVec4(0,0,0,220), "(%d,%d)", tx,ty);
ImGui_RenderText(ImGuiTextAlign_e::kAlignCenter, ImVec2((float)x, h-((float)y-25)), ImVec4(0,0,0,0.8f), "(%d,%d)", tx,ty);
}
// Tool help
const int h = view[3];
ImGui::SetCursorPos(ImVec2(280, (float)h-40));
ImGui::TextColored(ImVec4(255,255,255,192), "LMB: Rebuild hit tile. Shift+LMB: Clear hit tile.");
ImGui_RenderText(ImGuiTextAlign_e::kAlignLeft, ImVec2(280, 40),
ImVec4(1.0f,1.0f,1.0f,0.75f), "LMB: Rebuild hit tile. Shift+LMB: Clear hit tile.");
}
};
@ -756,13 +754,14 @@ void Editor_TileMesh::handleRender()
void Editor_TileMesh::handleRenderOverlay(double* proj, double* model, int* view)
{
GLdouble x, y, z;
const int h = view[3];
// Draw start and end point labels
if (m_tileBuildTime > 0.0f && gluProject((GLdouble)(m_lastBuiltTileBmin[0]+m_lastBuiltTileBmax[0])/2, (GLdouble)(m_lastBuiltTileBmin[1]+m_lastBuiltTileBmax[1])/2, (GLdouble)(m_lastBuiltTileBmin[2]+m_lastBuiltTileBmax[2])/2,
model, proj, view, &x, &y, &z))
{
ImGui::SetCursorPos(ImVec2((float)x, (float)y-25));
ImGui::TextColored(ImVec4(0,0,0,220), "%.3fms / %dTris / %.1fkB", m_tileBuildTime, m_tileTriCount, m_tileMemUsage);
ImGui_RenderText(ImGuiTextAlign_e::kAlignCenter, ImVec2((float)x, h-(float)(y-25)),
ImVec4(0,0,0,0.8f), "%.3fms / %dTris / %.1fkB", m_tileBuildTime, m_tileTriCount, m_tileMemUsage);
}
if (m_tool)

View File

@ -308,10 +308,8 @@ void NavMeshPruneTool::handleRenderOverlay(double* proj, double* model, int* vie
{
rcIgnoreUnused(model);
rcIgnoreUnused(proj);
rcIgnoreUnused(view);
// Tool help
const int h = view[3];
ImGui::SetCursorPos(ImVec2(280, (float)h-40));
ImGui::TextColored(ImVec4(255,255,255,192), "LMB: Click fill area.");
ImGui_RenderText(ImGuiTextAlign_e::kAlignLeft, ImVec2(280, 40), ImVec4(1.0f,1.0f,1.0f,0.75f), "LMB: Click fill area.");
}

View File

@ -1417,19 +1417,20 @@ void NavMeshTesterTool::handleRender()
void NavMeshTesterTool::handleRenderOverlay(double* proj, double* model, int* view)
{
GLdouble x, y, z;
const int h = view[3];
// Draw start and end point labels
if (m_sposSet && gluProject((GLdouble)m_spos[0], (GLdouble)m_spos[1], (GLdouble)m_spos[2],
model, proj, view, &x, &y, &z))
{
ImGui::SetCursorPos(ImVec2((float)x, (float)y-25));
ImGui::TextColored(ImVec4(0,0,0,220), "Start");
ImGui_RenderText(ImGuiTextAlign_e::kAlignCenter,
ImVec2((float)x, h-((float)y-25)), ImVec4(0,0,0,0.8f), "Start");
}
if (m_eposSet && gluProject((GLdouble)m_epos[0], (GLdouble)m_epos[1], (GLdouble)m_epos[2],
model, proj, view, &x, &y, &z))
{
ImGui::SetCursorPos(ImVec2((float)x, (float)y-25));
ImGui::TextColored(ImVec4(0,0,0,220), "End");
ImGui_RenderText(ImGuiTextAlign_e::kAlignCenter,
ImVec2((float)x, h-((float)y-25)), ImVec4(0,0,0,0.8f), "End");
}
// Useful utility to draw all polygroup id's at the center of the polygons.
@ -1457,19 +1458,16 @@ void NavMeshTesterTool::handleRenderOverlay(double* proj, double* model, int* vi
// if ((p.second) && gluProject((GLdouble)poly->center[0], (GLdouble)poly->center[1], (GLdouble)poly->center[2] + 30,
// model, proj, view, &x, &y, &z))
// {
// char label[6];
// snprintf(label, sizeof(label), "%hu", poly->groupId);
// ImGui::TextColored((int)x, (int)y, IMGUI_ALIGN_CENTER, label, ImVec4(0, 0, 0, 220));
// ImGui_RenderText(ImGuiTextAlign_e::kAlignCenter,
// ImVec2((float)x, h-(float)y), ImVec4(0, 0, 0, 0.8f), "%hu", poly->groupId);
// }
// }
// }
//}
// Tool help
const int h = view[3];
ImGui::SetCursorPos(ImVec2(280, (float)h-40));
ImGui::TextColored(ImVec4(255,255,255,192), "LMB+SHIFT: Set start location LMB: Set end location");
ImGui_RenderText(ImGuiTextAlign_e::kAlignLeft, ImVec2(280, 40),
ImVec4(1.0f,1.0f,1.0f,0.75f), "LMB+SHIFT: Set start location LMB: Set end location");
}
void NavMeshTesterTool::drawAgent(const float* pos, float r, float h, float c, const unsigned int col)

View File

@ -148,25 +148,24 @@ void OffMeshConnectionTool::handleRender()
void OffMeshConnectionTool::handleRenderOverlay(double* proj, double* model, int* view)
{
GLdouble x, y, z;
const int h = view[3];
// Draw start and end point labels
if (m_hitPosSet && gluProject((GLdouble)m_hitPos[0], (GLdouble)m_hitPos[1], (GLdouble)m_hitPos[2],
model, proj, view, &x, &y, &z))
{
ImGui::SetCursorPos(ImVec2((float)x, (float)y-25));
ImGui::TextColored(ImVec4(0,0,0,220), "Start");
ImGui_RenderText(ImGuiTextAlign_e::kAlignCenter, ImVec2((float)x, h-((float)y-25)), ImVec4(0,0,0,0.8f), "Start");
}
// Tool help
const int h = view[3];
if (!m_hitPosSet)
{
ImGui::SetCursorPos(ImVec2(280, (float)h-40));
ImGui::TextColored(ImVec4(255,255,255,192), "LMB: Create new connection. SHIFT+LMB: Delete existing connection, click close to start or end point.");
ImGui_RenderText(ImGuiTextAlign_e::kAlignLeft,
ImVec2(280, 40), ImVec4(1.0f,1.0f,1.0f,0.75f), "LMB: Create new connection. SHIFT+LMB: Delete existing connection, click close to start or end point.");
}
else
{
ImGui::SetCursorPos(ImVec2(280, (float)h-40));
ImGui::TextColored(ImVec4(255,255,255,192), "LMB: Set connection end point and finish.");
ImGui_RenderText(ImGuiTextAlign_e::kAlignLeft,
ImVec2(280, 40), ImVec4(1.0f,1.0f,1.0f,0.75f), "LMB: Set connection end point and finish.");
}
}

View File

@ -376,6 +376,7 @@ void TestCase::handleRender()
bool TestCase::handleRenderOverlay(double* proj, double* model, int* view)
{
GLdouble x, y, z;
const int h = view[3];
char text[256];
int n = 0;
@ -406,12 +407,11 @@ bool TestCase::handleRenderOverlay(double* proj, double* model, int* view)
if (gluProject((GLdouble)pt[0], (GLdouble)pt[1], (GLdouble)pt[2],
model, proj, view, &x, &y, &z))
{
ImVec4 col = ImVec4(0,0,0,128);
ImVec4 col = ImVec4(0.0f,0.0f,0.0f,0.5f);
if (iter->expand)
col = ImVec4(255,192,0,220);
col = ImVec4(1.0f,0.75f,0.0f,0.85f);
ImGui::SetCursorPos(ImVec2((float)x, (float)y-25));
ImGui::TextColored(col, "Path %d\n", n);
ImGui_RenderText(ImGuiTextAlign_e::kAlignCenter, ImVec2((float)x, h-((float)y-25)), col, "Path %d\n", n);
}
n++;
}

View File

@ -857,9 +857,8 @@ int not_main(int argc, char** argv)
// Help text.
if (showMenu)
{
// todo(amos): imgui
//ImGui::SetCursorPos(ImVec2(280, (float)height-20));
ImGui::TextColored(ImVec4(255,255,255,128), "W/S/A/D: Move RMB: Rotate", ImVec4(255,255,255,128));
ImGui_RenderText(ImGuiTextAlign_e::kAlignLeft,
ImVec2(280, 20), ImVec4(1.0f,1.0f,1.0f,0.5f), "W/S/A/D: Move RMB: Rotate");
}
string geom_path;

View File

@ -56,6 +56,7 @@
#include "thirdparty/imgui/imgui.h"
#include "thirdparty/imgui/imgui_internal.h"
#include "thirdparty/imgui/misc/imgui_style.h"
#include "thirdparty/imgui/misc/imgui_wrapper.h"
#include "thirdparty/imgui/misc/imgui_plotter.h"
#include "thirdparty/imgui/backends/imgui_impl_sdl2.h"
#include "thirdparty/imgui/backends/imgui_impl_opengl2.h"