diff --git a/makefile b/makefile index 2d92935..b396943 100644 --- a/makefile +++ b/makefile @@ -1,35 +1,52 @@ -# Compiler and flags -CXX := g++ -CXXFLAGS := -std=c++23 -O3 -march=native -I./imgui -LDFLAGS := -L./imgui -limgui -lstb -lGL -PKG_FLAGS := $(shell pkg-config --cflags --libs glfw3) - # Directories BIN_DIR := ./bin SRC_DIR := ./tests +IMGUI_DIR = ./imgui +OBJ_DIR := $(BIN_DIR)/obj +STB_DIR := ./stb + +# Compiler and flags +CXX := g++ +CXXFLAGS = -std=c++23 -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends -I$(STB_DIR) +#CXXFLAGS += -g -Wall -Wformat +CXXFLAGS += `pkg-config --cflags glfw3` +CFLAGS = $(CXXFLAGS) +LDFLAGS := -L./imgui -limgui -lGL +LINUX_GL_LIBS = -lGL +PKG_FLAGS := $(LINUX_GL_LIBS) `pkg-config --static --cflags --libs glfw3` +CXXFLAGS += $(PKG_FLAGS) # Source files SRC := $(SRC_DIR)/g2chromatic2.cpp -TARGET := $(BIN_DIR)/g2gradc +SRC += $(IMGUI_DIR)/imgui.cpp $(IMGUI_DIR)/imgui_demo.cpp $(IMGUI_DIR)/imgui_draw.cpp $(IMGUI_DIR)/imgui_tables.cpp $(IMGUI_DIR)/imgui_widgets.cpp +SRC += $(IMGUI_DIR)/backends/imgui_impl_glfw.cpp $(IMGUI_DIR)/backends/imgui_impl_opengl3.cpp +SRC += $(SRC_DIR)/stb_image.cpp +OBJS = $(addprefix $(OBJ_DIR)/, $(addsuffix .o, $(basename $(notdir $(SRC))))) +UNAME_S := $(shell uname -s) +EXE := $(BIN_DIR)/g2gradc -# Default target -all: $(TARGET) +$(shell mkdir -p $(OBJ_DIR)) -# Create binary directory if it doesn't exist -$(BIN_DIR): - @mkdir -p $(BIN_DIR) +$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp + $(CXX) $(CXXFLAGS) -c -o $@ $< -# Build target -$(TARGET): $(SRC) | $(BIN_DIR) - $(CXX) $(CXXFLAGS) -o $@ $< $(LDFLAGS) $(PKG_FLAGS) +$(OBJ_DIR)/%.o: %.cpp + $(CXX) $(CXXFLAGS) -c -o $@ $< -# Run the program -run: $(TARGET) - ./$(TARGET) +$(OBJ_DIR)/%.o: $(IMGUI_DIR)/%.cpp + $(CXX) $(CXXFLAGS) -c -o $@ $< + +$(OBJ_DIR)/%.o: $(IMGUI_DIR)/backends/%.cpp + $(CXX) $(CXXFLAGS) -c -o $@ $< + +$(OBJ_DIR)/%.o: $(STB_DIR)/%.cpp + $(CXX) $(CXXFLAGS) -c -o $@ $< + +all: $(EXE) + @echo Build complete for $(ECHO_MESSAGE) + +$(EXE): $(OBJS) + $(CXX) -o $@ $^ $(CXXFLAGS) $(LIBS) -# Clean build artifacts clean: - rm -rf $(BIN_DIR) - -# Phony targets -.PHONY: all run clean \ No newline at end of file + rm -f $(EXE) $(OBJS) \ No newline at end of file diff --git a/tests/g2chromatic2.cpp b/tests/g2chromatic2.cpp index 0d94935..5cfa16c 100644 --- a/tests/g2chromatic2.cpp +++ b/tests/g2chromatic2.cpp @@ -13,7 +13,6 @@ #include "../imgui/imgui.h" #include "../imgui/backends/imgui_impl_glfw.h" #include "../imgui/backends/imgui_impl_opengl3.h" -//#include "../imgui/" #include #include "../stb/stb_image.h" @@ -70,11 +69,11 @@ 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(); - std::vector framedata = Frame.getData(); +void livePreview(Grid2& grid) { + currentPreviewFrame = grid.getGridAsFrame(frame::colormap::RGB); + int image_width = currentPreviewFrame.getWidth(); + int image_height = currentPreviewFrame.getHeight(); + std::vector framedata = currentPreviewFrame.getData(); GLuint textu; glGenTextures(1, &textu); @@ -84,12 +83,7 @@ void livePreview(GLFWwindow* window, Grid2& grid) { glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image_width, image_height, 0, GL_RGB, GL_UNSIGNED_BYTE, framedata.data()); - ImGui::Begin(""); - //ImGui::Image((ImTextureRef)(intptr_t)textu, ImVec2(image_width, image_height)); - ImGui::Image(ImTextureRef((uint64_t)textu), ImVec2((float)image_width, (float)image_height)); - ImGui::End(); - - glDeleteTextures(1,&textu); + previewTexture = textu; } std::vector> pickSeeds(Grid2 grid, AnimationConfig config) { @@ -352,6 +346,7 @@ int main() { std::future mainlogicthread; Grid2 grid; + AnimationConfig config; while (!glfwWindowShouldClose(window)) { glfwPollEvents(); @@ -369,69 +364,50 @@ int main() { ImGui::SliderInt("framecount", &i3, 10, 5000); ImGui::SliderInt("numSeeds", &i4, 0, 10); - // Disable button while generating if (isGenerating) { ImGui::BeginDisabled(); } if (ImGui::Button("Generate Animation")) { - AnimationConfig config = AnimationConfig(i1, i2, i3, f, i4); + config = AnimationConfig(i1, i2, i3, f, i4); mainlogicthread = std::async(std::launch::async, mainLogic, config, std::ref(grid)); } if (isGenerating) { ImGui::EndDisabled(); - // Show cancel button and progress indicator ImGui::SameLine(); if (ImGui::Button("Cancel")) { cancelGeneration(); } - // Optional: Show a progress indicator ImGui::Text("Generating..."); } //ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate); // is this broken or is it just cause I have no refresh buffer in this loop? + + ImGui::Text("livepreview"); + if (isGenerating) { + livePreview(grid); + ImVec2 availableSize = ImGui::GetContentRegionAvail(); + + float aspectRatio = static_cast(currentPreviewFrame.getWidth()) / + static_cast(currentPreviewFrame.getHeight()); + + ImVec2 imageSize = ImVec2(config.height,config.width); + ImVec2 uv_min = ImVec2(0.0f, 0.0f); // Top-left + ImVec2 uv_max = ImVec2(1.0f, 1.0f); // Lower-right + auto ptex = const_cast(static_cast(currentPreviewFrame.getData().data())); + ImGui::ImageWithBg((ImTextureRef)ptex, imageSize, uv_min, uv_max, ImVec4(0.0f, 0.0f, 0.0f, 1.0f)); + + + } else { + ImGui::Text("No preview available"); + ImGui::Text("Start generation to see live preview"); + } + 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; diff --git a/tests/stb_image.cpp b/tests/stb_image.cpp new file mode 100644 index 0000000..badb3ef --- /dev/null +++ b/tests/stb_image.cpp @@ -0,0 +1,2 @@ +#define STB_IMAGE_IMPLEMENTATION +#include "stb_image.h" \ No newline at end of file