2017-09-15 19:25:47 +00:00
|
|
|
#include <imgui.h>
|
|
|
|
#include "imgui_impl_glfw_gl3.h"
|
|
|
|
#include <stdio.h>
|
2017-09-15 19:37:28 +00:00
|
|
|
#include <GL/gl3w.h>
|
2017-09-15 19:25:47 +00:00
|
|
|
#include <GLFW/glfw3.h>
|
2017-09-15 19:37:28 +00:00
|
|
|
#include <memory>
|
2017-09-30 12:32:30 +00:00
|
|
|
#include "../nfd/nfd.h"
|
2017-10-18 21:18:32 +00:00
|
|
|
#include <sys/stat.h>
|
2017-09-15 19:37:28 +00:00
|
|
|
|
2017-09-30 14:58:02 +00:00
|
|
|
#include "../../server/TracyFileRead.hpp"
|
2017-09-15 19:37:28 +00:00
|
|
|
#include "../../server/TracyView.hpp"
|
2017-09-15 19:25:47 +00:00
|
|
|
|
|
|
|
static void error_callback(int error, const char* description)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Error %d: %s\n", error, description);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int, char**)
|
|
|
|
{
|
|
|
|
// Setup window
|
|
|
|
glfwSetErrorCallback(error_callback);
|
|
|
|
if (!glfwInit())
|
|
|
|
return 1;
|
|
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
|
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
|
|
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
|
|
|
#if __APPLE__
|
|
|
|
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
|
|
|
#endif
|
2017-09-15 19:37:28 +00:00
|
|
|
GLFWwindow* window = glfwCreateWindow(1650, 960, "Tracy server", NULL, NULL);
|
2017-09-15 19:25:47 +00:00
|
|
|
glfwMakeContextCurrent(window);
|
|
|
|
glfwSwapInterval(1); // Enable vsync
|
|
|
|
gl3wInit();
|
|
|
|
|
|
|
|
// Setup ImGui binding
|
|
|
|
ImGui_ImplGlfwGL3_Init(window, true);
|
|
|
|
|
|
|
|
// Load Fonts
|
|
|
|
// (there is a default font, this is only if you want to change it. see extra_fonts/README.txt for more details)
|
|
|
|
//ImGuiIO& io = ImGui::GetIO();
|
|
|
|
//io.Fonts->AddFontDefault();
|
|
|
|
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f);
|
|
|
|
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f);
|
|
|
|
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyClean.ttf", 13.0f);
|
|
|
|
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f);
|
|
|
|
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
|
|
|
|
2017-10-18 21:18:32 +00:00
|
|
|
{
|
|
|
|
const char* font = "c:\\Windows\\Fonts\\arial.ttf";
|
|
|
|
struct stat st;
|
|
|
|
if( stat( font, &st ) == 0 )
|
|
|
|
{
|
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
|
|
io.Fonts->AddFontFromFileTTF( font, 15.0f );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-13 12:59:16 +00:00
|
|
|
ImGui::StyleColorsDark();
|
2018-01-13 13:08:14 +00:00
|
|
|
auto& style = ImGui::GetStyle();
|
|
|
|
style.WindowBorderSize = 1.f;
|
|
|
|
style.FrameBorderSize = 1.f;
|
|
|
|
style.Colors[ImGuiCol_WindowBg] = ImVec4( 0.11f, 0.11f, 0.08f, 0.94f );
|
|
|
|
style.Colors[ImGuiCol_ScrollbarBg] = ImVec4( 1, 1, 1, 0.03f );
|
2018-01-13 12:59:16 +00:00
|
|
|
|
2017-09-15 19:25:47 +00:00
|
|
|
ImVec4 clear_color = ImColor(114, 144, 154);
|
|
|
|
|
2017-09-15 19:37:28 +00:00
|
|
|
char addr[1024] = { "127.0.0.1" };
|
|
|
|
std::unique_ptr<tracy::View> view;
|
|
|
|
|
2017-09-15 19:25:47 +00:00
|
|
|
// Main loop
|
|
|
|
while (!glfwWindowShouldClose(window))
|
|
|
|
{
|
|
|
|
glfwPollEvents();
|
|
|
|
ImGui_ImplGlfwGL3_NewFrame();
|
|
|
|
|
2017-09-15 19:37:28 +00:00
|
|
|
if( !view )
|
2017-09-15 19:25:47 +00:00
|
|
|
{
|
2018-01-13 12:56:02 +00:00
|
|
|
ImGui::Begin( "Connect to...", nullptr, ImGuiWindowFlags_AlwaysAutoResize );
|
2017-09-15 19:37:28 +00:00
|
|
|
ImGui::InputText( "Address", addr, 1024 );
|
|
|
|
if( ImGui::Button( "Connect" ) && *addr )
|
|
|
|
{
|
|
|
|
view = std::make_unique<tracy::View>( addr );
|
|
|
|
}
|
2017-09-30 12:32:30 +00:00
|
|
|
ImGui::Separator();
|
|
|
|
if( ImGui::Button( "Open saved trace" ) )
|
|
|
|
{
|
|
|
|
nfdchar_t* fn;
|
|
|
|
auto res = NFD_OpenDialog( "tracy", nullptr, &fn );
|
|
|
|
if( res == NFD_OKAY )
|
|
|
|
{
|
2017-09-30 14:58:02 +00:00
|
|
|
auto f = std::unique_ptr<tracy::FileRead>( tracy::FileRead::Open( fn ) );
|
|
|
|
if( f )
|
|
|
|
{
|
|
|
|
view = std::make_unique<tracy::View>( *f );
|
|
|
|
}
|
2017-09-30 12:32:30 +00:00
|
|
|
}
|
|
|
|
}
|
2017-09-15 19:25:47 +00:00
|
|
|
ImGui::End();
|
|
|
|
}
|
2017-09-15 19:37:28 +00:00
|
|
|
else
|
2017-09-15 19:25:47 +00:00
|
|
|
{
|
2017-09-15 19:37:28 +00:00
|
|
|
view->Draw();
|
2017-09-15 19:25:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Rendering
|
|
|
|
int display_w, display_h;
|
|
|
|
glfwGetFramebufferSize(window, &display_w, &display_h);
|
|
|
|
glViewport(0, 0, display_w, display_h);
|
|
|
|
glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
ImGui::Render();
|
|
|
|
glfwSwapBuffers(window);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cleanup
|
|
|
|
ImGui_ImplGlfwGL3_Shutdown();
|
|
|
|
glfwTerminate();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#include <stdlib.h>
|
|
|
|
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmd, int nCmd )
|
|
|
|
{
|
|
|
|
return main( __argc, __argv );
|
|
|
|
}
|
|
|
|
#endif
|