added stuff

This commit is contained in:
2026-03-13 21:28:16 +03:00
parent 87966c82b9
commit f188257e0f
8 changed files with 169 additions and 3 deletions

View File

@@ -2,6 +2,7 @@ add_subdirectory(example_barycentric)
add_subdirectory(example_glfw3)
add_subdirectory(example_proj_mat_builder)
add_subdirectory(example_signature_scan)
add_subdirectory(example_hud)
if(OMATH_ENABLE_VALGRIND)
omath_setup_valgrind(example_projection_matrix_builder)

View File

@@ -0,0 +1,15 @@
project(example_hud)
add_executable(${PROJECT_NAME} main.cpp gui/main_window.cpp gui/main_window.hpp)
set_target_properties(${PROJECT_NAME} PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
CXX_STANDARD 23
CXX_STANDARD_REQUIRED ON)
find_package(OpenGL)
find_package(GLEW REQUIRED)
find_package(glfw3 CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE glfw imgui::imgui omath::omath OpenGL::GL)

View File

@@ -0,0 +1,110 @@
//
// Created by Orange on 11/11/2024.
//
#include "main_window.hpp"
#include "omath/hud/renderer_realizations/imgui_renderer.hpp"
#include <GLFW/glfw3.h>
#include <algorithm>
#include <imgui.h>
#include <imgui_impl_glfw.h>
#include <imgui_impl_opengl3.h>
#include <omath/hud/entity_overlay.hpp>
namespace imgui_desktop::gui
{
bool MainWindow::m_canMoveWindow = false;
MainWindow::MainWindow(const std::string_view& caption, int width, int height)
{
if (!glfwInit())
std::exit(EXIT_FAILURE);
glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, true);
m_window = glfwCreateWindow(width, height, caption.data(), nullptr, nullptr);
glfwMakeContextCurrent(m_window);
ImGui::CreateContext();
ImGui::StyleColorsDark();
ImGui::GetStyle().Colors[ImGuiCol_WindowBg] = {0.f, 0.f, 0.f, 0.f};
ImGui::GetStyle().AntiAliasedLines = false;
ImGui::GetStyle().AntiAliasedFill = false;
ImGui_ImplGlfw_InitForOpenGL(m_window, true);
ImGui_ImplOpenGL3_Init("#version 130");
}
void MainWindow::Run()
{
omath::Color box_color = {0.f, 0.f, 0.f, 1.f};
omath::Color box_fill = {0.f, 0.f, 0.f, 0.f};
omath::Color bar_color = {0.f, 1.f, 0.f, 1.f};
omath::Color bar_bg_color = {0.f, 0.f, 0.f, 0.0f};
omath::Color bar_outline_color = {0.f, 0.f, 0.f, 1.f};
float bar_width = 3.f;
float bar_value = 1.f;
while (!glfwWindowShouldClose(m_window) && m_opened)
{
glfwPollEvents();
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
ImGui::GetBackgroundDrawList()->AddRectFilled({}, ImGui::GetMainViewport()->Size, ImColor(40, 40, 40, 200));
ImGui::Begin("OHUD Showcase", &m_opened,
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoDecoration);
{
ImGui::SetWindowPos({});
ImGui::SetWindowSize(ImGui::GetMainViewport()->Size);
ImGui::ColorEdit4("Box", reinterpret_cast<float*>(&box_color), ImGuiColorEditFlags_NoInputs);
ImGui::ColorEdit4("Box fill", reinterpret_cast<float*>(&box_fill), ImGuiColorEditFlags_NoInputs);
ImGui::ColorEdit4("Bar", reinterpret_cast<float*>(&bar_color), ImGuiColorEditFlags_NoInputs);
ImGui::ColorEdit4("Bar Background", reinterpret_cast<float*>(&bar_bg_color),
ImGuiColorEditFlags_NoInputs);
ImGui::ColorEdit4("Bar Outline", reinterpret_cast<float*>(&bar_outline_color),
ImGuiColorEditFlags_NoInputs);
ImGui::PushItemWidth(100.f);
ImGui::SliderFloat("Bar Width", &bar_width, 1.f, 20.f);
ImGui::SliderFloat("Bar Value", &bar_value, 0.f, 1.f);
ImGui::PopItemWidth();
ImGui::End();
}
omath::hud::EntityOverlay ent({400.f, 100.f}, {400.f, 400.f}, std::make_shared<omath::hud::ImguiHudRenderer>());
ent.add_2d_box(box_color, box_fill, 1.f);
ent.add_cornered_2d_box(omath::Color::from_rgba(255, 0, 255, 255), box_fill);
ent.add_right_bar(bar_color, bar_outline_color, bar_bg_color, bar_width, bar_value);
ent.add_left_bar(bar_color, bar_outline_color, bar_bg_color, bar_width, bar_value);
ent.add_top_bar(bar_color, bar_outline_color, bar_bg_color, bar_width, bar_value);
ent.add_right_label({0.f, 1.f, 0.f, 1.f}, 3, true, "Health: {}/100", 100);
ent.add_right_label({1.f, 0.f, 0.f, 1.f}, 3, true, "Shield: {}/125", 125);
ent.add_right_label({1.f, 0.f, 1.f, 1.f}, 3, true, "*LOCKED*");
ent.add_top_label(omath::Color::from_rgba(255, 255, 0, 255), 3, true, "*SCOPED*");
ent.add_top_label(omath::Color::from_rgba(255, 0, 0, 255), 3, true, "*BLEEDING*");
ent.add_snap_line(omath::Vector2<float>{400, 600}, omath::Color::from_rgba(255, 0, 0, 255), 2.f);
ImGui::Render();
int display_w, display_h;
glfwGetFramebufferSize(m_window, &display_w, &display_h);
glViewport(0, 0, display_w, display_h);
glClearColor(0.f, 0.f, 0.f, 0.f);
glClear(GL_COLOR_BUFFER_BIT);
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
glfwSwapBuffers(m_window);
}
glfwDestroyWindow(m_window);
}
} // namespace imgui_desktop::gui
// imgui_desktop

View File

@@ -0,0 +1,28 @@
//
// Created by Vlad on 6/17/2025.
//
//
// Created by Orange on 11/11/2024.
//
#pragma once
#include <string_view>
struct GLFWwindow;
namespace imgui_desktop::gui
{
class MainWindow
{
public:
MainWindow(const std::string_view &caption, int width, int height);
void Run();
private:
GLFWwindow* m_window;
static bool m_canMoveWindow;
bool m_opened = true;
};
} // gui
// imgui_desktop

View File

@@ -0,0 +1,8 @@
//
// Created by orange on 13.03.2026.
//
#include "gui/main_window.hpp"
int main()
{
imgui_desktop::gui::MainWindow("omath::hud", 800, 600).Run();
}

View File

@@ -53,7 +53,7 @@ namespace omath::hud
void add_top_bar(const Color& color, const Color& outline_color, const Color& bg_color, float height,
float ratio, float offset = 5.f);
void add_snap_line(const Vector3<float>& start_pos, const Color& color, float width);
void add_snap_line(const Vector2<float>& start_pos, const Color& color, float width);
private:
void draw_outlined_text(const Vector2<float>& position, const Color& color,

View File

@@ -113,7 +113,7 @@ namespace omath::hud
m_text_cursor_top.y -= offset + height;
}
void EntityOverlay::add_snap_line(const Vector3<float>& start_pos, const Color& color, const float width)
void EntityOverlay::add_snap_line(const Vector2<float>& start_pos, const Color& color, const float width)
{
const Vector2<float> line_end =
m_canvas.bottom_left_corner

View File

@@ -31,7 +31,11 @@
"dependencies": [
"glfw3",
"glew",
"opengl"
"opengl",
{
"name": "imgui",
"features": ["glfw-binding", "opengl3-binding"]
}
]
},
"imgui": {