2024-04-22 21:00:51 +00:00
|
|
|
#include <glad/glad.h>
|
2024-03-27 13:04:19 +00:00
|
|
|
#include <GLFW/glfw3.h>
|
|
|
|
#include <iostream>
|
|
|
|
#include "imgui.h"
|
|
|
|
#include "imgui_impl_glfw.h"
|
|
|
|
#include "imgui_impl_opengl3.h"
|
|
|
|
|
2024-04-26 16:28:01 +00:00
|
|
|
// Global variables
|
2024-04-26 09:30:05 +00:00
|
|
|
std::string log_message;
|
2024-04-26 16:28:01 +00:00
|
|
|
int display_w = 800, display_h = 600;
|
2024-03-27 13:04:19 +00:00
|
|
|
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
|
|
|
|
|
2024-04-26 09:30:05 +00:00
|
|
|
void debug(std::string message){
|
2024-04-23 22:06:49 +00:00
|
|
|
log_message = message;
|
2024-03-27 13:04:19 +00:00
|
|
|
}
|
|
|
|
|
2024-04-26 09:30:05 +00:00
|
|
|
void show_menu(){
|
2024-03-27 13:04:19 +00:00
|
|
|
if(ImGui::BeginMainMenuBar()){
|
|
|
|
if(ImGui::BeginMenu("File")){
|
2024-04-26 16:28:01 +00:00
|
|
|
if (ImGui::MenuItem("Open..", "Ctrl+O")) { }
|
|
|
|
if (ImGui::MenuItem("Save", "Ctrl+S")) { }
|
|
|
|
if (ImGui::MenuItem("Close", "Ctrl+W")) { }
|
2024-03-27 13:04:19 +00:00
|
|
|
ImGui::EndMenu();
|
|
|
|
}
|
|
|
|
ImGui::EndMainMenuBar();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-26 09:30:05 +00:00
|
|
|
void show_hierarchy(){
|
|
|
|
ImGui::Begin("Hierarchy");
|
2024-03-27 13:04:19 +00:00
|
|
|
|
2024-04-26 09:30:05 +00:00
|
|
|
ImGui::End();
|
|
|
|
}
|
2024-03-27 13:04:19 +00:00
|
|
|
|
2024-04-26 09:30:05 +00:00
|
|
|
void show_project(){
|
|
|
|
ImGui::Begin("Project");
|
2024-03-27 13:04:19 +00:00
|
|
|
|
2024-04-26 09:30:05 +00:00
|
|
|
ImGui::End();
|
2024-03-27 13:04:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void show_console(){
|
|
|
|
ImGui::Begin("Console");
|
|
|
|
|
|
|
|
if(ImGui::Button("Clear")){
|
|
|
|
debug("");
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
|
|
|
if(ImGui::Button("Debug")){
|
|
|
|
debug("Debug message");
|
|
|
|
}
|
2024-04-26 09:30:05 +00:00
|
|
|
|
|
|
|
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
|
2024-03-27 13:04:19 +00:00
|
|
|
|
2024-04-23 22:06:49 +00:00
|
|
|
ImGui::Text("%s", log_message.c_str());
|
2024-03-27 13:04:19 +00:00
|
|
|
|
|
|
|
ImGui::End();
|
|
|
|
}
|
|
|
|
|
2024-04-26 09:30:05 +00:00
|
|
|
void show_scene(){
|
|
|
|
ImGui::Begin("Scene");
|
|
|
|
|
|
|
|
ImGui::End();
|
|
|
|
}
|
|
|
|
|
2024-03-27 13:04:19 +00:00
|
|
|
void show_inspector(){
|
2024-04-26 09:30:05 +00:00
|
|
|
static float f = 0.0f;
|
|
|
|
static int counter = 0;
|
|
|
|
|
2024-03-27 13:04:19 +00:00
|
|
|
ImGui::Begin("Inspector");
|
|
|
|
|
2024-04-26 16:28:01 +00:00
|
|
|
ImGui::Text("This is some useful text.");
|
2024-04-26 09:30:05 +00:00
|
|
|
|
2024-04-26 16:28:01 +00:00
|
|
|
ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
|
|
|
|
ImGui::ColorEdit3("clear color", (float*)&clear_color);
|
2024-04-26 09:30:05 +00:00
|
|
|
|
2024-04-26 16:28:01 +00:00
|
|
|
if (ImGui::Button("Button"))
|
2024-04-26 09:30:05 +00:00
|
|
|
counter++;
|
|
|
|
ImGui::SameLine();
|
|
|
|
ImGui::Text("counter = %d", counter);
|
|
|
|
|
2024-03-27 13:04:19 +00:00
|
|
|
ImGui::End();
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(void){
|
|
|
|
if(!glfwInit())
|
|
|
|
return -1;
|
2024-04-26 16:28:01 +00:00
|
|
|
|
|
|
|
GLFWwindow* window = glfwCreateWindow(display_w, display_h, "Ferx", NULL, NULL);
|
2024-03-27 13:04:19 +00:00
|
|
|
if(!window){
|
|
|
|
glfwTerminate();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
glfwMakeContextCurrent(window);
|
|
|
|
|
2024-04-22 21:00:51 +00:00
|
|
|
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
|
|
|
|
{
|
|
|
|
std::cout << "Failed to initialize GLAD" << std::endl;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2024-03-27 13:04:19 +00:00
|
|
|
IMGUI_CHECKVERSION();
|
|
|
|
ImGui::CreateContext();
|
|
|
|
ImGuiIO& io = ImGui::GetIO(); (void)io;
|
2024-04-26 16:28:01 +00:00
|
|
|
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
|
|
|
|
|
|
|
ImGuiStyle& style = ImGui::GetStyle();
|
|
|
|
ImVec4* colors = style.Colors;
|
2024-03-27 13:04:19 +00:00
|
|
|
ImGui::StyleColorsDark();
|
2024-04-26 16:28:01 +00:00
|
|
|
|
|
|
|
// Setup Platform/Renderer backends
|
2024-03-27 13:04:19 +00:00
|
|
|
ImGui_ImplGlfw_InitForOpenGL(window, true);
|
|
|
|
ImGui_ImplOpenGL3_Init();
|
|
|
|
|
|
|
|
while(!glfwWindowShouldClose(window)){
|
2024-04-26 16:28:01 +00:00
|
|
|
// Set up draw data for rendering
|
2024-03-27 13:04:19 +00:00
|
|
|
ImGui_ImplOpenGL3_NewFrame();
|
|
|
|
ImGui_ImplGlfw_NewFrame();
|
|
|
|
ImGui::NewFrame();
|
|
|
|
|
2024-04-26 16:28:01 +00:00
|
|
|
// Setup docking
|
|
|
|
ImGui::DockSpaceOverViewport(ImGui::GetMainViewport());
|
|
|
|
colors[ImGuiCol_DockingEmptyBg] = clear_color;
|
2024-03-27 13:04:19 +00:00
|
|
|
|
2024-04-26 16:28:01 +00:00
|
|
|
// Show windows
|
|
|
|
show_menu();
|
2024-04-26 09:30:05 +00:00
|
|
|
show_hierarchy();
|
|
|
|
show_scene();
|
|
|
|
show_project();
|
2024-03-27 13:04:19 +00:00
|
|
|
show_console();
|
2024-04-26 09:30:05 +00:00
|
|
|
show_inspector();
|
|
|
|
|
2024-03-27 13:04:19 +00:00
|
|
|
// Rendering
|
|
|
|
ImGui::Render();
|
|
|
|
glfwGetFramebufferSize(window, &display_w, &display_h);
|
|
|
|
glViewport(0, 0, display_w, display_h);
|
|
|
|
glClearColor(clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w);
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
|
|
|
|
2024-04-26 16:28:01 +00:00
|
|
|
ImGui::EndFrame();
|
|
|
|
|
2024-03-27 13:04:19 +00:00
|
|
|
glfwSwapBuffers(window);
|
2024-04-26 16:28:01 +00:00
|
|
|
glfwPollEvents();
|
2024-03-27 13:04:19 +00:00
|
|
|
}
|
2024-04-26 16:28:01 +00:00
|
|
|
|
|
|
|
// Cleanup
|
|
|
|
ImGui_ImplOpenGL3_Shutdown();
|
|
|
|
ImGui_ImplGlfw_Shutdown();
|
|
|
|
ImGui::DestroyContext();
|
2024-03-27 13:04:19 +00:00
|
|
|
|
2024-04-26 16:28:01 +00:00
|
|
|
glfwDestroyWindow(window);
|
|
|
|
glfwTerminate();
|
2024-03-27 13:04:19 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|