init commit
This commit is contained in:
@@ -0,0 +1,130 @@
|
||||
#include "ui_main.h"
|
||||
|
||||
#include <SDL3/SDL_opengl.h>
|
||||
|
||||
#include <imgui/imgui.h>
|
||||
#include "imgui/imgui_impl_sdl3.h"
|
||||
#include "imgui/imgui_impl_opengl3.h"
|
||||
|
||||
#include "scene/dvu_load_gltf.h"
|
||||
#include "pipe/dvc_render_queue.h"
|
||||
#include "device/dvc_render_target.h"
|
||||
#include "shader/dvc_shader_interface.h"
|
||||
#include "buffer/dvu_dump_buffer.h"
|
||||
#include "device/dvc_uniform_buffer.h"
|
||||
#include "scene/dvc_scene_node.h"
|
||||
#include "scene/component/dvc_light_component.h"
|
||||
#include "../adapter/adapter_texture.h"
|
||||
|
||||
|
||||
SDL_Window* main_window;
|
||||
|
||||
extern davinci::Scene g_scene;
|
||||
extern davinci::RenderTarget g_renderTarget;
|
||||
|
||||
bool initMainUI(SDL_Window* window, SDL_GLContext gl_context, const char* glsl_version)
|
||||
{
|
||||
main_window = window;
|
||||
|
||||
// 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
|
||||
|
||||
// Setup Dear ImGui style
|
||||
//ImGui::StyleColorsDark();
|
||||
ImGui::StyleColorsLight();
|
||||
|
||||
// Setup Platform/Renderer backends
|
||||
ImGui_ImplSDL3_InitForOpenGL(window, gl_context);
|
||||
ImGui_ImplOpenGL3_Init(glsl_version);
|
||||
|
||||
// Load Fonts
|
||||
// - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
||||
// - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple.
|
||||
// - If the file cannot be loaded, the function will return a nullptr. Please handle those errors in your application (e.g. use an assertion, or display an error and quit).
|
||||
// - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call.
|
||||
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use Freetype for higher quality font rendering.
|
||||
// - Read 'docs/FONTS.md' for more instructions and details.
|
||||
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
||||
// - Our Emscripten build process allows embedding fonts to be accessible at runtime from the "fonts/" folder. See Makefile.emscripten for details.
|
||||
//io.Fonts->AddFontDefault();
|
||||
io.Fonts->AddFontFromFileTTF("./font/FiraCode-Regular.ttf", 18.0f);
|
||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f);
|
||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f);
|
||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f);
|
||||
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, nullptr, io.Fonts->GetGlyphRangesJapanese());
|
||||
//IM_ASSERT(font != nullptr);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void processUIEvent(const SDL_Event* event)
|
||||
{
|
||||
ImGui_ImplSDL3_ProcessEvent(event);
|
||||
}
|
||||
|
||||
void OpenFileDialogFileCallback(void* userdata, const char* const* filelist, int filter)
|
||||
{
|
||||
if (filelist == nullptr || *filelist == nullptr) return;
|
||||
|
||||
g_scene.clear();
|
||||
|
||||
const char* szFileName = *filelist;
|
||||
davinci_utils::load_scene_from_gltf(szFileName, g_scene);
|
||||
}
|
||||
|
||||
void drawMainUI()
|
||||
{
|
||||
// Start the Dear ImGui frame
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui_ImplSDL3_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
|
||||
ImGui::Begin("Davinci"); // Create a window called "Hello, world!" and append into it.
|
||||
if (ImGui::Button("OpenFile..."))
|
||||
{
|
||||
const SDL_DialogFileFilter filters[] = {
|
||||
{ "gltf files(*.gltf;*.glb)", "gltf;glb" },
|
||||
{ "All files(*.*)", "*" }
|
||||
};
|
||||
SDL_ShowOpenFileDialog(OpenFileDialogFileCallback, nullptr, main_window, filters, sizeof(filters)/sizeof(SDL_DialogFileFilter), nullptr, false);
|
||||
}
|
||||
if (ImGui::Button("Export"))
|
||||
{
|
||||
davinci_utils::export_mesh_to_obj(g_scene);
|
||||
}
|
||||
if (ImGui::Button("Render"))
|
||||
{
|
||||
davinci::UniformBuffer uniformBuffer;
|
||||
uniformBuffer.updateStandardAttribute(g_scene);
|
||||
|
||||
//find Light node
|
||||
davinci::SceneNodeConstPtr lightNode = g_scene.getNodeWithComponent<davinci::LightComponent>();
|
||||
if (lightNode)
|
||||
{
|
||||
uniformBuffer.setAttribute("light0:position", lightNode->getWorldPosition());
|
||||
}
|
||||
|
||||
davinci::RenderQueue queue;
|
||||
queue.build(g_scene);
|
||||
|
||||
g_renderTarget.clear();
|
||||
queue.process(uniformBuffer, g_renderTarget);
|
||||
}
|
||||
ImGui::End();
|
||||
|
||||
// Rendering
|
||||
ImGui::Render();
|
||||
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
}
|
||||
|
||||
void cleanMainUI()
|
||||
{
|
||||
ImGui_ImplOpenGL3_Shutdown();
|
||||
ImGui_ImplSDL3_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
}
|
||||
Reference in New Issue
Block a user