added imgui and fmt, started working on ui
This commit is contained in:
78
src/main.cpp
78
src/main.cpp
@@ -12,6 +12,9 @@
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "Components.h"
|
||||
#include "FreeCamera.h"
|
||||
#include "imgui.h"
|
||||
#include "imgui_impl_glfw.h"
|
||||
#include "imgui_impl_opengl3.h"
|
||||
#include "InputManager.h"
|
||||
#include "stb_image.h"
|
||||
|
||||
@@ -23,9 +26,11 @@
|
||||
#include "Texture.h"
|
||||
#include "TextureManager.h"
|
||||
|
||||
#include "fmt/base.h"
|
||||
|
||||
GLFWwindow* gWindow = nullptr;
|
||||
int gWindowWidth = 800;
|
||||
int gWindowHeight = 600;
|
||||
int gWindowWidth = 1920;
|
||||
int gWindowHeight = 1080;
|
||||
|
||||
int glVersionMajor = 0;
|
||||
int glVersionMinor = 0;
|
||||
@@ -45,12 +50,14 @@ void glfw_framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
||||
void init_glfw();
|
||||
void create_main_window();
|
||||
void load_gl();
|
||||
void load_imgui();
|
||||
void init_camera();
|
||||
void load_default_textures();
|
||||
void load_shaders();
|
||||
void load_inputs();
|
||||
void load_default_models();
|
||||
void loop();
|
||||
void draw_ui();
|
||||
|
||||
auto xAxis = glm::vec3{1.f, 0.f, 0.f};
|
||||
auto yAxis = glm::vec3{0.f, 1.f, 0.f};
|
||||
@@ -65,6 +72,8 @@ int main() {
|
||||
|
||||
load_gl();
|
||||
|
||||
load_imgui();
|
||||
|
||||
init_camera();
|
||||
|
||||
stbi_set_flip_vertically_on_load(true);
|
||||
@@ -84,6 +93,9 @@ int main() {
|
||||
diffuse = {0.5f, 0.5f, 0.5f};
|
||||
specular = {1.0f, 1.0f, 1.0f};
|
||||
|
||||
auto& tag = gScene.fetch_component<Components::Tag>(dirLight);
|
||||
tag.name = "directional light";
|
||||
|
||||
loop();
|
||||
|
||||
ShaderManager::shaders.clear();
|
||||
@@ -159,6 +171,15 @@ void load_gl()
|
||||
glEnable(GL_MULTISAMPLE);
|
||||
}
|
||||
|
||||
void load_imgui() {
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
|
||||
ImGui::StyleColorsDark();
|
||||
ImGui_ImplGlfw_InitForOpenGL(gWindow, true);
|
||||
ImGui_ImplOpenGL3_Init("#version 330");
|
||||
}
|
||||
|
||||
void init_camera() {
|
||||
gCamera = {{5.f, 5.f, 5.f}, 0, 0, gAspectRatio};
|
||||
gCamera.rotate_yaw(-135.f);
|
||||
@@ -241,10 +262,14 @@ void loop() {
|
||||
gCamera.move(DOWN, .05);
|
||||
}
|
||||
|
||||
draw_ui();
|
||||
|
||||
// gl frame prep
|
||||
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
|
||||
const auto shader = ShaderManager::shaders["phong_shader"];
|
||||
shader->bind();
|
||||
shader->setMat4("projection", gCamera.projection());
|
||||
@@ -259,4 +284,53 @@ void loop() {
|
||||
// gl end frame stuff
|
||||
glfwSwapBuffers(gWindow);
|
||||
}
|
||||
}
|
||||
|
||||
void draw_ui() {
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui_ImplGlfw_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
{
|
||||
if (ImGui::Begin("Scene")) {
|
||||
ImGui::Text("Scene");
|
||||
const auto root = gScene.get_root();
|
||||
auto entity = gScene.fetch_component<Components::Relationship>(root).first_child;
|
||||
while (entity != entt::null) {
|
||||
const auto&[name] = gScene.fetch_component<Components::Tag>(entity);
|
||||
std::string text = fmt::format(" {0}", name);
|
||||
ImGui::Text((char*)text.data());
|
||||
entity = gScene.fetch_component<Components::Relationship>(entity).next_sibling;
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
if (ImGui::BeginMainMenuBar()) {
|
||||
if (ImGui::BeginMenu("File")) {
|
||||
if (ImGui::MenuItem("New Scene", "Ctrl+N")) {
|
||||
/* Handle New File logic */
|
||||
}
|
||||
if (ImGui::MenuItem("Open Scene", "Ctrl+O")) {
|
||||
/* Handle Open logic */
|
||||
}
|
||||
ImGui::Separator(); // Adds a visual line between sections
|
||||
if (ImGui::MenuItem("Save", "Ctrl+S")) {
|
||||
/* Handle Save logic */
|
||||
}
|
||||
if (ImGui::MenuItem("Exit", "Alt+F4")) {
|
||||
/* Handle Exit logic */
|
||||
}
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
if (ImGui::BeginMenu("Scene")) {
|
||||
if (ImGui::MenuItem("New Scene Object")) {
|
||||
gScene.create_game_object();
|
||||
// Do other stuff here, open this entity in the entity editor, etc...
|
||||
}
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
ImGui::EndMainMenuBar();
|
||||
}
|
||||
}
|
||||
ImGui::Render();
|
||||
}
|
||||
Reference in New Issue
Block a user