JuliaSets/src/Application.cpp

64 lines
1.3 KiB
C++
Raw Normal View History

2022-02-18 15:06:16 +00:00
#include <glad/glad.h>
#include "Application.hpp"
#include <stdexcept>
2022-02-18 15:28:20 +00:00
#include "backends/imgui_impl_glfw.h"
#include "backends/imgui_impl_opengl3.h"
2022-02-18 15:06:16 +00:00
Application::Application() :
2022-02-18 15:28:20 +00:00
window(new Window(1280, 720, "Mandelbrot")), canvas(nullptr), backgroundColor{ 0.1f, 0.01f, 0.19f }
2022-02-18 15:06:16 +00:00
{
window->MakeContextCurrent();
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
{
throw std::runtime_error("GLAD failed to initialize.");
}
glViewport(0, 0, 1280, 720);
canvas = new Canvas();
2022-02-18 15:28:20 +00:00
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO();
window->InitImGui();
ImGui_ImplOpenGL3_Init("#version 460 core");
ImGui::StyleColorsDark();
2022-02-18 15:06:16 +00:00
}
Application::~Application()
{
2022-02-18 15:28:20 +00:00
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
2022-02-18 15:06:16 +00:00
}
void Application::Launch()
{
while (!window->ShouldClose())
{
glfwPollEvents();
2022-02-18 15:28:20 +00:00
glClearColor(backgroundColor[0], backgroundColor[1], backgroundColor[2], 1.0f);
2022-02-18 15:06:16 +00:00
glClear(GL_COLOR_BUFFER_BIT);
2022-02-18 15:28:20 +00:00
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
2022-02-18 15:06:16 +00:00
canvas->Render();
2022-02-18 15:28:20 +00:00
ImGui::Begin("Settings");
ImGui::SliderFloat3("Background Color", backgroundColor, 0.0f, 1.0f);
ImGui::End();
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
2022-02-18 15:06:16 +00:00
window->Display();
}
}