stupid makefile stuff. well, it kinda works now. still no live preview but checkpointing it here.
This commit is contained in:
63
makefile
63
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
|
# Directories
|
||||||
BIN_DIR := ./bin
|
BIN_DIR := ./bin
|
||||||
SRC_DIR := ./tests
|
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
|
# Source files
|
||||||
SRC := $(SRC_DIR)/g2chromatic2.cpp
|
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
|
$(shell mkdir -p $(OBJ_DIR))
|
||||||
all: $(TARGET)
|
|
||||||
|
|
||||||
# Create binary directory if it doesn't exist
|
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
|
||||||
$(BIN_DIR):
|
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||||
@mkdir -p $(BIN_DIR)
|
|
||||||
|
|
||||||
# Build target
|
$(OBJ_DIR)/%.o: %.cpp
|
||||||
$(TARGET): $(SRC) | $(BIN_DIR)
|
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||||
$(CXX) $(CXXFLAGS) -o $@ $< $(LDFLAGS) $(PKG_FLAGS)
|
|
||||||
|
|
||||||
# Run the program
|
$(OBJ_DIR)/%.o: $(IMGUI_DIR)/%.cpp
|
||||||
run: $(TARGET)
|
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||||
./$(TARGET)
|
|
||||||
|
$(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:
|
clean:
|
||||||
rm -rf $(BIN_DIR)
|
rm -f $(EXE) $(OBJS)
|
||||||
|
|
||||||
# Phony targets
|
|
||||||
.PHONY: all run clean
|
|
||||||
@@ -13,7 +13,6 @@
|
|||||||
#include "../imgui/imgui.h"
|
#include "../imgui/imgui.h"
|
||||||
#include "../imgui/backends/imgui_impl_glfw.h"
|
#include "../imgui/backends/imgui_impl_glfw.h"
|
||||||
#include "../imgui/backends/imgui_impl_opengl3.h"
|
#include "../imgui/backends/imgui_impl_opengl3.h"
|
||||||
//#include "../imgui/"
|
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
#include "../stb/stb_image.h"
|
#include "../stb/stb_image.h"
|
||||||
|
|
||||||
@@ -70,11 +69,11 @@ void Preview(Grid2& grid) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void livePreview(GLFWwindow* window, Grid2& grid) {
|
void livePreview(Grid2& grid) {
|
||||||
frame Frame = grid.getGridAsFrame(frame::colormap::RGB);
|
currentPreviewFrame = grid.getGridAsFrame(frame::colormap::RGB);
|
||||||
int image_width = Frame.getWidth();
|
int image_width = currentPreviewFrame.getWidth();
|
||||||
int image_height = Frame.getHeight();
|
int image_height = currentPreviewFrame.getHeight();
|
||||||
std::vector<uint8_t> framedata = Frame.getData();
|
std::vector<uint8_t> framedata = currentPreviewFrame.getData();
|
||||||
|
|
||||||
GLuint textu;
|
GLuint textu;
|
||||||
glGenTextures(1, &textu);
|
glGenTextures(1, &textu);
|
||||||
@@ -84,12 +83,7 @@ void livePreview(GLFWwindow* window, Grid2& grid) {
|
|||||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
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());
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image_width, image_height, 0, GL_RGB, GL_UNSIGNED_BYTE, framedata.data());
|
||||||
|
|
||||||
ImGui::Begin("");
|
previewTexture = textu;
|
||||||
//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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::tuple<size_t, Vec2, Vec4>> pickSeeds(Grid2 grid, AnimationConfig config) {
|
std::vector<std::tuple<size_t, Vec2, Vec4>> pickSeeds(Grid2 grid, AnimationConfig config) {
|
||||||
@@ -352,6 +346,7 @@ int main() {
|
|||||||
|
|
||||||
std::future<void> mainlogicthread;
|
std::future<void> mainlogicthread;
|
||||||
Grid2 grid;
|
Grid2 grid;
|
||||||
|
AnimationConfig config;
|
||||||
while (!glfwWindowShouldClose(window)) {
|
while (!glfwWindowShouldClose(window)) {
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
|
||||||
@@ -369,68 +364,49 @@ int main() {
|
|||||||
ImGui::SliderInt("framecount", &i3, 10, 5000);
|
ImGui::SliderInt("framecount", &i3, 10, 5000);
|
||||||
ImGui::SliderInt("numSeeds", &i4, 0, 10);
|
ImGui::SliderInt("numSeeds", &i4, 0, 10);
|
||||||
|
|
||||||
// Disable button while generating
|
|
||||||
if (isGenerating) {
|
if (isGenerating) {
|
||||||
ImGui::BeginDisabled();
|
ImGui::BeginDisabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ImGui::Button("Generate Animation")) {
|
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));
|
mainlogicthread = std::async(std::launch::async, mainLogic, config, std::ref(grid));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isGenerating) {
|
if (isGenerating) {
|
||||||
ImGui::EndDisabled();
|
ImGui::EndDisabled();
|
||||||
|
|
||||||
// Show cancel button and progress indicator
|
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
if (ImGui::Button("Cancel")) {
|
if (ImGui::Button("Cancel")) {
|
||||||
cancelGeneration();
|
cancelGeneration();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Optional: Show a progress indicator
|
|
||||||
ImGui::Text("Generating...");
|
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("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::End();
|
|
||||||
|
ImGui::Text("livepreview");
|
||||||
|
if (isGenerating) {
|
||||||
|
livePreview(grid);
|
||||||
|
ImVec2 availableSize = ImGui::GetContentRegionAvail();
|
||||||
|
|
||||||
|
float aspectRatio = static_cast<float>(currentPreviewFrame.getWidth()) /
|
||||||
|
static_cast<float>(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<void*>(static_cast<const void*>(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::NewFrame();
|
ImGui::End();
|
||||||
// {
|
}
|
||||||
// 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<float>(currentPreviewFrame.getWidth()) /
|
|
||||||
// static_cast<float>(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();
|
ImGui::Render();
|
||||||
|
|||||||
2
tests/stb_image.cpp
Normal file
2
tests/stb_image.cpp
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
|
#include "stb_image.h"
|
||||||
Reference in New Issue
Block a user