You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
176 lines
3.8 KiB
C++
176 lines
3.8 KiB
C++
#include <stdio.h>
|
|
|
|
#ifdef __EMSCRIPTEN__
|
|
#include <emscripten.h>
|
|
#include <emscripten/html5.h>
|
|
#endif
|
|
|
|
#define GLFW_INCLUDE_ES3
|
|
#include <GLES3/gl3.h>
|
|
#include <GLFW/glfw3.h>
|
|
|
|
#include "imgui.h"
|
|
#include "imgui_impl_glfw.h"
|
|
#include "imgui_impl_opengl3.h"
|
|
#include <iostream>
|
|
#include "hud_elements.h"
|
|
#include "overlay.h"
|
|
#include "font_default.h"
|
|
#include "faker.h"
|
|
|
|
GLFWwindow* g_window;
|
|
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
|
|
bool show_demo_window = true;
|
|
bool show_another_window = false;
|
|
int g_width;
|
|
int g_height;
|
|
swapchain_stats sw_stats {};
|
|
overlay_params params {};
|
|
static ImVec2 window_size;
|
|
static uint32_t vendorID;
|
|
static std::string deviceName;
|
|
static int msgid;
|
|
static bool mangoapp_paused = false;
|
|
|
|
// Function used by c++ to get the size of the html canvas
|
|
EM_JS(int, canvas_get_width, (), {
|
|
return Module.canvas.width;
|
|
});
|
|
|
|
// Function used by c++ to get the size of the html canvas
|
|
EM_JS(int, canvas_get_height, (), {
|
|
return Module.canvas.height;
|
|
});
|
|
|
|
// Function called by javascript
|
|
EM_JS(void, resizeCanvas, (), {
|
|
js_resizeCanvas();
|
|
});
|
|
|
|
void on_size_changed()
|
|
{
|
|
glfwSetWindowSize(g_window, g_width, g_height);
|
|
|
|
ImGui::SetCurrentContext(ImGui::GetCurrentContext());
|
|
}
|
|
|
|
void loop()
|
|
{
|
|
int width = canvas_get_width();
|
|
int height = canvas_get_height();
|
|
|
|
if (width != g_width || height != g_height)
|
|
{
|
|
g_width = width;
|
|
g_height = height;
|
|
on_size_changed();
|
|
}
|
|
|
|
glfwPollEvents();
|
|
|
|
ImGui_ImplOpenGL3_NewFrame();
|
|
ImGui_ImplGlfw_NewFrame();
|
|
ImGui::NewFrame();
|
|
update_hud_info(sw_stats, params, vendorID);
|
|
overlay_new_frame(params);
|
|
position_layer(sw_stats, params, window_size);
|
|
render_imgui(sw_stats, params, window_size, true);
|
|
overlay_end_frame();
|
|
ImGui::Render();
|
|
|
|
int display_w, display_h;
|
|
glfwMakeContextCurrent(g_window);
|
|
glfwGetFramebufferSize(g_window, &display_w, &display_h);
|
|
glViewport(0, 0, display_w, display_h);
|
|
EmscriptenWebGLContextAttributes attrs;
|
|
emscripten_webgl_init_context_attributes(&attrs);
|
|
attrs.alpha = EM_TRUE;
|
|
glEnable(GL_DEPTH_TEST);
|
|
glEnable(GL_BLEND);
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
glClearColor(0, 0, 0, 0.8);
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
|
glfwMakeContextCurrent(g_window);
|
|
}
|
|
|
|
int init_gl()
|
|
{
|
|
if( !glfwInit() )
|
|
{
|
|
fprintf( stderr, "Failed to initialize GLFW\n" );
|
|
return 1;
|
|
}
|
|
|
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // We don't want the old OpenGL
|
|
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
|
|
glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, 1);
|
|
|
|
// Open a window and create its OpenGL context
|
|
int canvasWidth = g_width;
|
|
int canvasHeight = g_height;
|
|
g_window = glfwCreateWindow(canvasWidth, canvasHeight, "WebGui Demo", NULL, NULL);
|
|
if( g_window == NULL )
|
|
{
|
|
fprintf( stderr, "Failed to open GLFW window.\n" );
|
|
glfwTerminate();
|
|
return -1;
|
|
}
|
|
glfwMakeContextCurrent(g_window); // Initialize GLEW
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
int init_imgui()
|
|
{
|
|
// Setup Dear ImGui binding
|
|
IMGUI_CHECKVERSION();
|
|
ImGui::CreateContext();
|
|
ImGui_ImplGlfw_InitForOpenGL(g_window, true);
|
|
ImGui_ImplOpenGL3_Init();
|
|
|
|
// Setup style
|
|
// ImGui::StyleColorsDark();
|
|
|
|
create_fonts(nullptr, params, sw_stats.font1, sw_stats.font_text);
|
|
parse_overlay_config(¶ms, "MANGOHUD_CONFIG", false);
|
|
HUDElements.convert_colors(params);
|
|
sw_stats.engine = EngineTypes::VULKAN;
|
|
faker = std::make_unique<Faker>(sw_stats, params, vendorID);
|
|
resizeCanvas();
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
int init()
|
|
{
|
|
init_gl();
|
|
init_imgui();
|
|
return 0;
|
|
}
|
|
|
|
|
|
void quit()
|
|
{
|
|
glfwTerminate();
|
|
}
|
|
|
|
|
|
extern "C" int main(int argc, char** argv)
|
|
{
|
|
g_width = canvas_get_width();
|
|
g_height = canvas_get_height();
|
|
if (init() != 0) return 1;
|
|
|
|
#ifdef __EMSCRIPTEN__
|
|
emscripten_set_main_loop(loop, 0, 1);
|
|
#endif
|
|
|
|
quit();
|
|
|
|
return 0;
|
|
}
|