text: #include "crocpch.h"
  #include "ImGuiLayer.h"
  
  #include "imgui.h"
  #include "examples/imgui_impl_glfw.h"
  #include "examples/imgui_impl_opengl3.h"
  
  #include "Croc/Core/Application.h"
  
  //TEMPORARY
  #include <GLFW/glfw3.h>
  #include <glad/glad.h>
  
  namespace Croc {
  
  	ImGuiLayer::ImGuiLayer()
  		: Layer("ImGuiLayer")
  	{
  	}
  
  	ImGuiLayer::~ImGuiLayer()
  	{
  	}
  
  	void ImGuiLayer::OnAttach()
  	{
  		CROC_PROFILE_FUNCTION();
  		// Setup Dear ImGui context
  		IMGUI_CHECKVERSION();
  		ImGui::CreateContext();
  		ImGuiIO& io = ImGui::GetIO(); (void)io;
  		io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;       // Enable Keyboard Controls
  		//io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;      // Enable Gamepad Controls
  		io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;           // Enable Docking
  		io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;         // Enable Multi-Viewport / Platform Windows
  		//io.ConfigViewportsNoAutoMerge = true;
  		//io.ConfigViewportsNoTaskBarIcon = true;
  
  		// Setup Dear ImGui style
  		ImGui::StyleColorsDark();
  		//ImGui::StyleColorsClassic();
  
  		// When viewports are enabled we tweak WindowRounding/WindowBg so platform windows can look identical to regular ones.
  		ImGuiStyle& style = ImGui::GetStyle();
  		if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
  		{
  			style.WindowRounding = 0.0f;
  			style.Colors[ImGuiCol_WindowBg].w = 1.0f;
  		}
  
  		Application& app = Application::Get();
  		GLFWwindow* window = static_cast<GLFWwindow*>(app.GetWindow().GetNativeWindow());
  		
  		ImGui_ImplGlfw_InitForOpenGL(window, true);
  		ImGui_ImplOpenGL3_Init("#version 410");
  	}
  
  
  	void ImGuiLayer::OnDetach()
  	{
  		CROC_PROFILE_FUNCTION();
  		ImGui_ImplOpenGL3_Shutdown();
  		ImGui_ImplGlfw_Shutdown();
  		ImGui::DestroyContext();
  	}
  
  	void ImGuiLayer::Begin() 
  	{
  		CROC_PROFILE_FUNCTION();
  		ImGui_ImplOpenGL3_NewFrame();
  		ImGui_ImplGlfw_NewFrame();
  		ImGui::NewFrame();
  	}
  
  	void ImGuiLayer::End()
  	{
  		CROC_PROFILE_FUNCTION();
  
  		ImGuiIO& io = ImGui::GetIO();
  		Application& app = Application::Get();
  		io.DisplaySize = ImVec2((float)app.GetWindow().GetWidth(), (float)app.GetWindow().GetHeight());
  
  		// Rendering
  		ImGui::Render();
  		ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
  
  		if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) 
  		{
  			GLFWwindow* backup_current_context = glfwGetCurrentContext();
  			ImGui::UpdatePlatformWindows();
  			ImGui::RenderPlatformWindowsDefault();
  			glfwMakeContextCurrent(backup_current_context);
  		}
  	}
  
  }