|
|
|
@@ -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!
|
|
|
|
|
|
|
|
|
|
mandelbrot_shader = Shader(VertexShaderFilepathFromPrefixName("test"), FragmentShaderFilepathFromPrefixName("mandelbrot"));
|
|
|
|
|
julia_shader = Shader(VertexShaderFilepathFromPrefixName("test" ), FragmentShaderFilepathFromPrefixName("julia"));
|
|
|
|
|
mandelbrot_shader = new Shader(VertexShaderFilepathFromPrefixName("test"), FragmentShaderFilepathFromPrefixName("mandelbrot"));
|
|
|
|
|
julia_shader = new Shader(VertexShaderFilepathFromPrefixName("test" ), FragmentShaderFilepathFromPrefixName("julia"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FractalInspectorApp::ReloadShader() {
|
|
|
|
@@ -118,7 +118,7 @@ void OpenURL(const std::string &url) {
|
|
|
|
|
JUI::Window * FractalInspectorApp::CreateAppInfoDialogWindow(JUI::Widget *parent) {
|
|
|
|
|
// TODO: Implement JUI structure that makes blocks of text easy to impelement.
|
|
|
|
|
auto window = new JUI::Window(parent);
|
|
|
|
|
window->SetTitle("About FractalInspector");
|
|
|
|
|
window->Title("About FractalInspector");
|
|
|
|
|
window->Size({300_px, 375_px});
|
|
|
|
|
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* content = new JUI::TextRect(layout);
|
|
|
|
|
content->Size({100_percent, JUI::UDim(size+5, 0)});
|
|
|
|
|
content->SetContent(text);
|
|
|
|
|
content->SetTextSize(size);
|
|
|
|
|
content->SetTextColor(color);
|
|
|
|
|
content->Content(text);
|
|
|
|
|
content->TextSize(size);
|
|
|
|
|
content->TextColor(color);
|
|
|
|
|
content->BGColor(Colors::Transparent);
|
|
|
|
|
content->AlignCenterHorizontally();
|
|
|
|
|
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* {
|
|
|
|
|
JUI::TextButton* btn = new JUI::TextButton(btn_layout);
|
|
|
|
|
btn->SetContent(text);
|
|
|
|
|
btn->Content(text);
|
|
|
|
|
btn->Size({32_percent, 100_percent});
|
|
|
|
|
btn->SetTextColor(Colors::Black);
|
|
|
|
|
btn->TextColor(Colors::Black);
|
|
|
|
|
btn->Center();
|
|
|
|
|
btn->OnClickEvent += [callback] (auto a, auto b) {
|
|
|
|
|
callback();
|
|
|
|
@@ -199,10 +199,12 @@ void FractalInspectorApp::CreateMenu() {
|
|
|
|
|
fractals_list->AddButton("Mandelbrot set", [this]{
|
|
|
|
|
UnloadJulia();
|
|
|
|
|
current_fractal = Fractal::MandelbrotSet;
|
|
|
|
|
current_shader = mandelbrot_shader;
|
|
|
|
|
});
|
|
|
|
|
fractals_list->AddButton("Julia set", [this]{
|
|
|
|
|
LoadJulia();
|
|
|
|
|
current_fractal = Fractal::JuliaSet;
|
|
|
|
|
current_shader = julia_shader;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -250,12 +252,12 @@ void FractalInspectorApp::CreateMenu() {
|
|
|
|
|
fps_label = new JUI::TextRect(toolbar);
|
|
|
|
|
fps_label->Position({100_percent - 200_px, 0_px});
|
|
|
|
|
fps_label->Size({200_px, 100_percent});
|
|
|
|
|
fps_label->SetTextColor(Colors::Black);
|
|
|
|
|
fps_label->SetContent("60 FPS");
|
|
|
|
|
fps_label->TextColor(Colors::Black);
|
|
|
|
|
fps_label->Content("60 FPS");
|
|
|
|
|
|
|
|
|
|
// TODO: Utilize for things later.
|
|
|
|
|
colorpicker_window = new JUI::Window(scene);
|
|
|
|
|
colorpicker_window->SetTitle("Color-Pickers");
|
|
|
|
|
colorpicker_window->Title("Color-Pickers");
|
|
|
|
|
colorpicker_window->MinSize({300, 150});
|
|
|
|
|
colorpicker_window->Size({400_px, 150_px});
|
|
|
|
|
colorpicker_window->Position({50_px, 50_px});
|
|
|
|
@@ -318,9 +320,9 @@ void FractalInspectorApp::CreateMenu() {
|
|
|
|
|
|
|
|
|
|
auto* content = new JUI::TextRect(mandelbrotset_layout);
|
|
|
|
|
content->Size({100_percent, 25_px});
|
|
|
|
|
content->SetContent(text);
|
|
|
|
|
content->SetTextSize(size);
|
|
|
|
|
content->SetTextColor(color);
|
|
|
|
|
content->Content(text);
|
|
|
|
|
content->TextSize(size);
|
|
|
|
|
content->TextColor(color);
|
|
|
|
|
content->BGColor(Colors::Transparent);
|
|
|
|
|
content->AlignCenterHorizontally();
|
|
|
|
|
content->LayoutOrder(idx--);
|
|
|
|
@@ -353,41 +355,26 @@ void FractalInspectorApp::CreateMenu() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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->Size({900_px, 70_px});
|
|
|
|
|
juliaset_dialog->Close(); // Defaults to close.
|
|
|
|
|
|
|
|
|
|
julia_x_slider = new JUI::Slider(juliaset_dialog->Content());
|
|
|
|
|
julia_x_label = new JUI::Text(julia_x_slider);
|
|
|
|
|
|
|
|
|
|
julia_x_label->AlignCenterHorizontally();
|
|
|
|
|
julia_x_label->AlignTop();
|
|
|
|
|
julia_x_label->SetTextColor(Colors::Black);
|
|
|
|
|
julia_x_label->SetContent("X: 0");
|
|
|
|
|
auto* julia_x_slider = new JUI::Slider(juliaset_dialog->Content());
|
|
|
|
|
|
|
|
|
|
julia_x_slider->Size({900_px, 25_px});
|
|
|
|
|
julia_x_slider->Interval(1e-5f); julia_x_slider->Minimum(0); julia_x_slider->Maximum(1);
|
|
|
|
|
julia_x_slider->ValueChanged += [this] (double value) {
|
|
|
|
|
julia_x_label->SetContent(std::format("X: {}", Math::FloorInt(value*360)));
|
|
|
|
|
value = value * 2;
|
|
|
|
|
value = value - 1;
|
|
|
|
|
u_julia_set.x = value;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
julia_y_slider = new JUI::Slider(juliaset_dialog->Content());
|
|
|
|
|
julia_y_label = new JUI::Text(julia_y_slider);
|
|
|
|
|
|
|
|
|
|
julia_y_label->AlignCenterHorizontally();
|
|
|
|
|
julia_y_label->AlignTop();
|
|
|
|
|
julia_y_label->SetTextColor(Colors::Black);
|
|
|
|
|
julia_y_label->SetContent("Y: 0");
|
|
|
|
|
|
|
|
|
|
auto* julia_y_slider = new JUI::Slider(juliaset_dialog->Content());
|
|
|
|
|
julia_y_slider->Size({900_px, 25_px});
|
|
|
|
|
julia_y_slider->Position({0_px, 30_px});
|
|
|
|
|
julia_y_slider->Interval(1e-5f); julia_y_slider->Minimum(0); julia_y_slider->Maximum(1);
|
|
|
|
|
julia_y_slider->ValueChanged += [this] (double value) {
|
|
|
|
|
julia_y_label->SetContent(std::format("Y: {}", Math::FloorInt(value*360)));
|
|
|
|
|
value = value * 2;
|
|
|
|
|
value = value - 1;
|
|
|
|
|
u_julia_set.y = value;
|
|
|
|
@@ -555,7 +542,7 @@ void FractalInspectorApp::Update(float elapsed) {
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
fps_label->SetContent(fps_text);
|
|
|
|
|
fps_label->Content(fps_text);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -571,25 +558,25 @@ void FractalInspectorApp::UpdateShaderUniforms(float elapsed) {
|
|
|
|
|
// TODO: Why do we need to multiply X by 1.5 here?
|
|
|
|
|
Vector2 u_mouse = Vector2(GetMouseCoordinates().x*1.5f, GetSize().y-GetMouseCoordinates().y);
|
|
|
|
|
|
|
|
|
|
JGL::Shader shader;
|
|
|
|
|
;
|
|
|
|
|
if (current_fractal == Fractal::JuliaSet) {
|
|
|
|
|
shader = julia_shader;
|
|
|
|
|
shader.SetVector2("u_julia_set", u_julia_value);
|
|
|
|
|
current_shader = julia_shader;
|
|
|
|
|
julia_shader->SetVector2("u_julia_set", u_julia_value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (current_fractal == Fractal::MandelbrotSet) {
|
|
|
|
|
shader = mandelbrot_shader;
|
|
|
|
|
current_shader = mandelbrot_shader;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
shader.SetVector2("u_resolution", u_res);
|
|
|
|
|
shader.SetFloat("u_time", u_time);
|
|
|
|
|
shader.SetVector2("u_mouse", u_mouse);
|
|
|
|
|
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()));
|
|
|
|
|
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()));
|
|
|
|
|
shader.SetFloat("u_scale", u_scale);
|
|
|
|
|
shader.SetVector2("u_translation", u_translation);
|
|
|
|
|
current_shader->SetVector2("u_resolution", u_res);
|
|
|
|
|
current_shader->SetFloat("u_time", u_time);
|
|
|
|
|
current_shader->SetVector2("u_mouse", u_mouse);
|
|
|
|
|
current_shader->SetVector3("u_rgb_1", Vector3(u_rgb_1.RN(), u_rgb_1.GN(), u_rgb_1.BN()));
|
|
|
|
|
current_shader->SetVector3("u_rgb_2", Vector3(u_rgb_2.RN(), u_rgb_2.GN(), u_rgb_2.BN()));
|
|
|
|
|
current_shader->SetVector3("u_rgb_3", Vector3(u_rgb_3.RN(), u_rgb_3.GN(), u_rgb_3.BN()));
|
|
|
|
|
current_shader->SetVector3("u_rgb_4", Vector3(u_rgb_4.RN(), u_rgb_4.GN(), u_rgb_4.BN()));
|
|
|
|
|
current_shader->SetFloat("u_scale", u_scale);
|
|
|
|
|
current_shader->SetVector2("u_translation", u_translation);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Vector2 solve(Vector2 a, Vector2 b) {
|
|
|
|
@@ -604,7 +591,8 @@ Vector2 solve(Vector2 a, Vector2 b) {
|
|
|
|
|
|
|
|
|
|
void FractalInspectorApp::Draw() {
|
|
|
|
|
|
|
|
|
|
Shader::UseDefault();
|
|
|
|
|
//Shader::SetDefault(); // TODO: Was this deprecated or replaced?
|
|
|
|
|
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
|
glLoadIdentity();
|
|
|
|
@@ -616,7 +604,6 @@ void FractalInspectorApp::Draw() {
|
|
|
|
|
J2D::DrawRenderTarget(canvas, {0, 0});
|
|
|
|
|
J2D::End();
|
|
|
|
|
|
|
|
|
|
// This is annoying, leaving note here to comment it out when I work on this - maxine
|
|
|
|
|
J2D::Begin();
|
|
|
|
|
|
|
|
|
|
const float N = 512.f;
|
|
|
|
@@ -659,15 +646,10 @@ void FractalInspectorApp::Draw() {
|
|
|
|
|
|
|
|
|
|
scene->Draw();
|
|
|
|
|
|
|
|
|
|
JGL::J2D::Begin(canvas, true);
|
|
|
|
|
if (current_fractal == Fractal::JuliaSet) {
|
|
|
|
|
julia_shader.Use();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (current_fractal == Fractal::MandelbrotSet) {
|
|
|
|
|
mandelbrot_shader.Use();
|
|
|
|
|
}
|
|
|
|
|
JGL::J2D::FillRect(Colors::Black, {0, 0}, Vector2(GetSize().x, GetSize().y));
|
|
|
|
|
JGL::J2D::Begin(canvas, current_shader, true);
|
|
|
|
|
|
|
|
|
|
JGL::J2D::FillRect(Colors::White, {0, 0}, Vector2(GetSize().x, GetSize().y));
|
|
|
|
|
JGL::J2D::End();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|