2 Commits

3 changed files with 50 additions and 51 deletions

View File

@@ -30,10 +30,10 @@ CPMAddPackage(NAME ReWindow
URL https://git.redacted.cc/Redacted/ReWindow/archive/Prerelease-32.zip) URL https://git.redacted.cc/Redacted/ReWindow/archive/Prerelease-32.zip)
CPMAddPackage(NAME JGL CPMAddPackage(NAME JGL
URL https://git.redacted.cc/josh/JGL/archive/Prerelease-55.zip) URL https://git.redacted.cc/josh/JGL/archive/Prerelease-58.zip)
CPMAddPackage(NAME JUI CPMAddPackage(NAME JUI
URL https://git.redacted.cc/josh/ReJUI/archive/Prerelease-6.zip) URL https://git.redacted.cc/josh/ReJUI/archive/Prerelease-6.4.zip)
file(COPY "shaders" DESTINATION "${PROJECT_BINARY_DIR}") file(COPY "shaders" DESTINATION "${PROJECT_BINARY_DIR}")
#file(GLOB_RECURSE ASSETS "assets/") #file(GLOB_RECURSE ASSETS "assets/")

View File

@@ -54,19 +54,19 @@ inline void Lerped<Vector2>::Update(float elapsed) { current = Vector2::Lerp(cur
/// This class represents the FractalApp program state. /// This class represents the FractalApp program state.
class FractalInspectorApp : public ReWindow::OpenGLWindow { class FractalInspectorApp : public ReWindow::OpenGLWindow {
protected: protected:
JUI::Scene *scene; JUI::Scene *scene = nullptr;
JUI::UtilityBar* toolbar; JUI::UtilityBar* toolbar = nullptr;
JUI::CommandLine *console; JUI::CommandLine *console = nullptr;
JUI::Window* info_dialog; JUI::Window* info_dialog = nullptr;
JUI::TextRect* fps_label; JUI::TextRect* fps_label = nullptr;
JUI::Window* mandelbrotset_dialog; JUI::Window* mandelbrotset_dialog = nullptr;
JUI::Window* juliaset_dialog; JUI::Window* juliaset_dialog = nullptr;
JUI::Window* colorpicker_window; JUI::Window* colorpicker_window = nullptr;
JGL::Shader mandelbrot_shader; JGL::Shader* mandelbrot_shader = nullptr;
JGL::Shader julia_shader; JGL::Shader* julia_shader = nullptr;
JGL::RenderTarget *canvas; JGL::RenderTarget *canvas = nullptr;
float u_time; float u_time;
float u_scale = 2.f; float u_scale = 2.f;
float u_scale_goal = 2.f; float u_scale_goal = 2.f;
@@ -81,6 +81,7 @@ protected:
bool panning = false; bool panning = false;
Fractal current_fractal = Fractal::MandelbrotSet; Fractal current_fractal = Fractal::MandelbrotSet;
JGL::Shader* current_shader;
void OnShaderLoadFail(const std::string&, const std::string&); void OnShaderLoadFail(const std::string&, const std::string&);
public: public:

View File

@@ -31,8 +31,8 @@ void FractalInspectorApp::LoadShaders() {
// TODO: Come up with a decent way to bake the shader program sources into the executable, when compiling a release build! // TODO: Come up with a decent way to bake the shader program sources into the executable, when compiling a release build!
mandelbrot_shader = Shader(VertexShaderFilepathFromPrefixName("test"), FragmentShaderFilepathFromPrefixName("mandelbrot")); mandelbrot_shader = new Shader(VertexShaderFilepathFromPrefixName("test"), FragmentShaderFilepathFromPrefixName("mandelbrot"));
julia_shader = Shader(VertexShaderFilepathFromPrefixName("test" ), FragmentShaderFilepathFromPrefixName("julia")); julia_shader = new Shader(VertexShaderFilepathFromPrefixName("test" ), FragmentShaderFilepathFromPrefixName("julia"));
} }
void FractalInspectorApp::ReloadShader() { void FractalInspectorApp::ReloadShader() {
@@ -118,7 +118,7 @@ void OpenURL(const std::string &url) {
JUI::Window * FractalInspectorApp::CreateAppInfoDialogWindow(JUI::Widget *parent) { JUI::Window * FractalInspectorApp::CreateAppInfoDialogWindow(JUI::Widget *parent) {
// TODO: Implement JUI structure that makes blocks of text easy to impelement. // TODO: Implement JUI structure that makes blocks of text easy to impelement.
auto window = new JUI::Window(parent); auto window = new JUI::Window(parent);
window->SetTitle("About FractalInspector"); window->Title("About FractalInspector");
window->Size({300_px, 375_px}); window->Size({300_px, 375_px});
window->MinSize({300, 375}); window->MinSize({300, 375});
@@ -131,9 +131,9 @@ JUI::Window * FractalInspectorApp::CreateAppInfoDialogWindow(JUI::Widget *parent
auto line_item = [&] (const std::string& text, int size = 20, const Color4& color = Colors::White) { auto line_item = [&] (const std::string& text, int size = 20, const Color4& color = Colors::White) {
auto* content = new JUI::TextRect(layout); auto* content = new JUI::TextRect(layout);
content->Size({100_percent, JUI::UDim(size+5, 0)}); content->Size({100_percent, JUI::UDim(size+5, 0)});
content->SetContent(text); content->Content(text);
content->SetTextSize(size); content->TextSize(size);
content->SetTextColor(color); content->TextColor(color);
content->BGColor(Colors::Transparent); content->BGColor(Colors::Transparent);
content->AlignCenterHorizontally(); content->AlignCenterHorizontally();
content->BorderWidth(0); content->BorderWidth(0);
@@ -170,9 +170,9 @@ JUI::Window * FractalInspectorApp::CreateAppInfoDialogWindow(JUI::Widget *parent
auto btn_item = [&] (const std::string& text, const std::function<void()>& callback = {}) -> JUI::TextButton* { auto btn_item = [&] (const std::string& text, const std::function<void()>& callback = {}) -> JUI::TextButton* {
JUI::TextButton* btn = new JUI::TextButton(btn_layout); JUI::TextButton* btn = new JUI::TextButton(btn_layout);
btn->SetContent(text); btn->Content(text);
btn->Size({32_percent, 100_percent}); btn->Size({32_percent, 100_percent});
btn->SetTextColor(Colors::Black); btn->TextColor(Colors::Black);
btn->Center(); btn->Center();
btn->OnClickEvent += [callback] (auto a, auto b) { btn->OnClickEvent += [callback] (auto a, auto b) {
callback(); callback();
@@ -199,10 +199,12 @@ void FractalInspectorApp::CreateMenu() {
fractals_list->AddButton("Mandelbrot set", [this]{ fractals_list->AddButton("Mandelbrot set", [this]{
UnloadJulia(); UnloadJulia();
current_fractal = Fractal::MandelbrotSet; current_fractal = Fractal::MandelbrotSet;
current_shader = mandelbrot_shader;
}); });
fractals_list->AddButton("Julia set", [this]{ fractals_list->AddButton("Julia set", [this]{
LoadJulia(); LoadJulia();
current_fractal = Fractal::JuliaSet; current_fractal = Fractal::JuliaSet;
current_shader = julia_shader;
}); });
@@ -250,12 +252,12 @@ void FractalInspectorApp::CreateMenu() {
fps_label = new JUI::TextRect(toolbar); fps_label = new JUI::TextRect(toolbar);
fps_label->Position({100_percent - 200_px, 0_px}); fps_label->Position({100_percent - 200_px, 0_px});
fps_label->Size({200_px, 100_percent}); fps_label->Size({200_px, 100_percent});
fps_label->SetTextColor(Colors::Black); fps_label->TextColor(Colors::Black);
fps_label->SetContent("60 FPS"); fps_label->Content("60 FPS");
// TODO: Utilize for things later. // TODO: Utilize for things later.
colorpicker_window = new JUI::Window(scene); colorpicker_window = new JUI::Window(scene);
colorpicker_window->SetTitle("Color-Pickers"); colorpicker_window->Title("Color-Pickers");
colorpicker_window->MinSize({300, 150}); colorpicker_window->MinSize({300, 150});
colorpicker_window->Size({400_px, 150_px}); colorpicker_window->Size({400_px, 150_px});
colorpicker_window->Position({50_px, 50_px}); colorpicker_window->Position({50_px, 50_px});
@@ -318,9 +320,9 @@ void FractalInspectorApp::CreateMenu() {
auto* content = new JUI::TextRect(mandelbrotset_layout); auto* content = new JUI::TextRect(mandelbrotset_layout);
content->Size({100_percent, 25_px}); content->Size({100_percent, 25_px});
content->SetContent(text); content->Content(text);
content->SetTextSize(size); content->TextSize(size);
content->SetTextColor(color); content->TextColor(color);
content->BGColor(Colors::Transparent); content->BGColor(Colors::Transparent);
content->AlignCenterHorizontally(); content->AlignCenterHorizontally();
content->LayoutOrder(idx--); content->LayoutOrder(idx--);
@@ -353,7 +355,7 @@ void FractalInspectorApp::CreateMenu() {
juliaset_dialog = new JUI::Window(scene); juliaset_dialog = new JUI::Window(scene);
juliaset_dialog->SetTitle("Julia Set Inputs"); juliaset_dialog->Title("Julia Set Inputs");
juliaset_dialog->Position({20_px, 300_px}); juliaset_dialog->Position({20_px, 300_px});
juliaset_dialog->Size({900_px, 70_px}); juliaset_dialog->Size({900_px, 70_px});
juliaset_dialog->Close(); // Defaults to close. juliaset_dialog->Close(); // Defaults to close.
@@ -540,7 +542,7 @@ void FractalInspectorApp::Update(float elapsed) {
std::string fps_text = std::format("Pos: {},{} Zoom: {}x FPS: {}", std::string fps_text = std::format("Pos: {},{} Zoom: {}x FPS: {}",
Math::Round(u_translation.x, 4), Math::Round(u_translation.y, 4), readable_scale, fps); Math::Round(u_translation.x, 4), Math::Round(u_translation.y, 4), readable_scale, fps);
fps_label->SetContent(fps_text); fps_label->Content(fps_text);
@@ -556,25 +558,25 @@ void FractalInspectorApp::UpdateShaderUniforms(float elapsed) {
// TODO: Why do we need to multiply X by 1.5 here? // TODO: Why do we need to multiply X by 1.5 here?
Vector2 u_mouse = Vector2(GetMouseCoordinates().x*1.5f, GetSize().y-GetMouseCoordinates().y); Vector2 u_mouse = Vector2(GetMouseCoordinates().x*1.5f, GetSize().y-GetMouseCoordinates().y);
JGL::Shader shader; ;
if (current_fractal == Fractal::JuliaSet) { if (current_fractal == Fractal::JuliaSet) {
shader = julia_shader; current_shader = julia_shader;
shader.SetVector2("u_julia_set", u_julia_value); julia_shader->SetVector2("u_julia_set", u_julia_value);
} }
if (current_fractal == Fractal::MandelbrotSet) { if (current_fractal == Fractal::MandelbrotSet) {
shader = mandelbrot_shader; current_shader = mandelbrot_shader;
} }
shader.SetVector2("u_resolution", u_res); current_shader->SetVector2("u_resolution", u_res);
shader.SetFloat("u_time", u_time); current_shader->SetFloat("u_time", u_time);
shader.SetVector2("u_mouse", u_mouse); current_shader->SetVector2("u_mouse", u_mouse);
shader.SetVector3("u_rgb_1", Vector3(u_rgb_1.RN(), u_rgb_1.GN(), u_rgb_1.BN())); current_shader->SetVector3("u_rgb_1", Vector3(u_rgb_1.RN(), u_rgb_1.GN(), u_rgb_1.BN()));
shader.SetVector3("u_rgb_2", Vector3(u_rgb_2.RN(), u_rgb_2.GN(), u_rgb_2.BN())); current_shader->SetVector3("u_rgb_2", Vector3(u_rgb_2.RN(), u_rgb_2.GN(), u_rgb_2.BN()));
shader.SetVector3("u_rgb_3", Vector3(u_rgb_3.RN(), u_rgb_3.GN(), u_rgb_3.BN())); current_shader->SetVector3("u_rgb_3", Vector3(u_rgb_3.RN(), u_rgb_3.GN(), u_rgb_3.BN()));
shader.SetVector3("u_rgb_4", Vector3(u_rgb_4.RN(), u_rgb_4.GN(), u_rgb_4.BN())); current_shader->SetVector3("u_rgb_4", Vector3(u_rgb_4.RN(), u_rgb_4.GN(), u_rgb_4.BN()));
shader.SetFloat("u_scale", u_scale); current_shader->SetFloat("u_scale", u_scale);
shader.SetVector2("u_translation", u_translation); current_shader->SetVector2("u_translation", u_translation);
} }
Vector2 solve(Vector2 a, Vector2 b) { Vector2 solve(Vector2 a, Vector2 b) {
@@ -589,7 +591,8 @@ Vector2 solve(Vector2 a, Vector2 b) {
void FractalInspectorApp::Draw() { void FractalInspectorApp::Draw() {
Shader::UseDefault(); //Shader::SetDefault(); // TODO: Was this deprecated or replaced?
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); glLoadIdentity();
@@ -643,15 +646,10 @@ void FractalInspectorApp::Draw() {
scene->Draw(); scene->Draw();
JGL::J2D::Begin(canvas, true);
if (current_fractal == Fractal::JuliaSet) {
julia_shader.Use();
}
if (current_fractal == Fractal::MandelbrotSet) { JGL::J2D::Begin(canvas, current_shader, true);
mandelbrot_shader.Use();
} JGL::J2D::FillRect(Colors::White, {0, 0}, Vector2(GetSize().x, GetSize().y));
JGL::J2D::FillRect(Colors::Black, {0, 0}, Vector2(GetSize().x, GetSize().y));
JGL::J2D::End(); JGL::J2D::End();
} }