diff --git a/tests/g2chromatic2.cpp b/tests/g2chromatic2.cpp index 3b4b53b..1485cdf 100644 --- a/tests/g2chromatic2.cpp +++ b/tests/g2chromatic2.cpp @@ -14,6 +14,7 @@ #include "../imgui/backends/imgui_impl_glfw.h" #include "../imgui/backends/imgui_impl_opengl3.h" #include +#include "../stb/stb_image.h" #include #include @@ -24,6 +25,11 @@ std::mutex m; std::atomic isGenerating{false}; std::future generationFuture; +std::mutex previewMutex; +std::atomic updatePreview{false}; +frame currentPreviewFrame; +GLuint previewTexture = 0; + struct AnimationConfig { int width = 1024; int height = 1024; @@ -50,7 +56,7 @@ Grid2 setup(AnimationConfig config) { return grid; } -void Preview(Grid2 grid) { +void Preview(Grid2& grid) { TIME_FUNCTION; int width; int height; @@ -63,6 +69,14 @@ void Preview(Grid2 grid) { } } +void livePreview(GLFWwindow* window, Grid2& grid) { + // frame Frame = grid.getGridAsFrame(frame::colormap::RGB); + // int image_width = Frame.getWidth(); + // int image_height = Frame.getHeight(); + // auto data = reinterpret_cast(Frame.getData()); + // uint8_t* image_data = stbi_load_from_memory((const unsigned char*)data, (int)data.size(), &image_width, &image_height, 3, 4); +} + std::vector> pickSeeds(Grid2 grid, AnimationConfig config) { TIME_FUNCTION; std::random_device rd; @@ -187,12 +201,12 @@ bool exportavi(std::vector frames, AnimationConfig config) { return success; } -void mainLogic(const AnimationConfig& config) { +void mainLogic(const AnimationConfig& config, Grid2& grid) { isGenerating = true; try { - Grid2 grid = setup(config); + grid = setup(config); Preview(grid); - std::vector> seeds = pickSeeds(grid,config); + std::vector> seeds = pickSeeds(grid, config); std::vector frames; for (int i = 0; i < config.totalFrames; ++i){ @@ -322,6 +336,7 @@ int main() { static int i4 = 8; std::future mainlogicthread; + Grid2 grid; while (!glfwWindowShouldClose(window)) { glfwPollEvents(); @@ -329,8 +344,6 @@ int main() { ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplGlfw_NewFrame(); ImGui::NewFrame(); - - { ImGui::Begin("Gradient settings"); @@ -348,7 +361,7 @@ int main() { if (ImGui::Button("Generate Animation")) { AnimationConfig config = AnimationConfig(i1, i2, i3, f, i4); - mainlogicthread = std::async(std::launch::async, mainLogic, config); + mainlogicthread = std::async(std::launch::async, mainLogic, config, std::ref(grid)); } if (isGenerating) { @@ -367,6 +380,43 @@ int main() { ImGui::End(); } + // ImGui::NewFrame(); + // { + // ImGui::Begin("Live Preview"); + + // if (previewTexture != 0) { + // // Get available space + // ImVec2 availableSize = ImGui::GetContentRegionAvail(); + + // // Maintain aspect ratio (assuming square or config width/height) + // float aspectRatio = static_cast(currentPreviewFrame.getWidth()) / + // static_cast(currentPreviewFrame.getHeight()); + + // ImVec2 imageSize; + // if (availableSize.x / aspectRatio <= availableSize.y) { + // imageSize.x = availableSize.x; + // imageSize.y = availableSize.x / aspectRatio; + // } else { + // imageSize.y = availableSize.y; + // imageSize.x = availableSize.y * aspectRatio; + // } + + // ImGui::Image((ImTextureID)(intptr_t)previewTexture, imageSize); + + // ImGui::Text("Frame: %dx%d", currentPreviewFrame.getWidth(), currentPreviewFrame.getHeight()); + // if (isGenerating) { + // ImGui::TextColored(ImVec4(0, 1, 0, 1), "Generating..."); + // } else { + // ImGui::Text("Ready"); + // } + // } else { + // ImGui::Text("No preview available"); + // ImGui::Text("Start generation to see live preview"); + // } + + // ImGui::End(); + // } + ImGui::Render(); int display_w, display_h; @@ -386,6 +436,10 @@ int main() { ImGui::DestroyContext(); glfwDestroyWindow(window); + if (previewTexture != 0) { + glDeleteTextures(1, &previewTexture); + previewTexture = 0; + } glfwTerminate(); FunctionTimer::printStats(FunctionTimer::Mode::ENHANCED); return 0;