2024-04-11 20:40:12 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2024 Brett Terpstra
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <blt/gfx/window.h>
|
|
|
|
#include "blt/gfx/renderer/resource_manager.h"
|
|
|
|
#include "blt/gfx/renderer/batch_2d_renderer.h"
|
|
|
|
#include "blt/gfx/renderer/camera.h"
|
2024-04-16 16:07:54 -04:00
|
|
|
#include <blt/gfx/framebuffer.h>
|
2024-05-01 03:27:37 -04:00
|
|
|
#include <blt/gfx/raycast.h>
|
2024-04-11 20:40:12 -04:00
|
|
|
#include <imgui.h>
|
2024-04-30 15:04:07 -04:00
|
|
|
#include <memory>
|
2024-04-30 02:47:58 -04:00
|
|
|
#include <random>
|
|
|
|
#include <blt/std/ranges.h>
|
|
|
|
#include <blt/std/time.h>
|
|
|
|
#include <blt/math/log_util.h>
|
2024-05-03 02:46:02 -04:00
|
|
|
#include <blt/gfx/input.h>
|
2024-05-09 13:49:27 -04:00
|
|
|
#include <blt/parse/templating.h>
|
2024-05-14 02:58:25 -04:00
|
|
|
#include <graph.h>
|
2024-05-09 13:49:27 -04:00
|
|
|
#include <blt/gfx/renderer/shaders/pp_screen.frag>
|
2024-05-02 00:32:58 -04:00
|
|
|
|
2024-04-11 20:40:12 -04:00
|
|
|
blt::gfx::matrix_state_manager global_matrices;
|
|
|
|
blt::gfx::resource_manager resources;
|
2024-05-05 17:03:59 -04:00
|
|
|
blt::gfx::batch_renderer_2d renderer_2d(resources, global_matrices);
|
2024-04-30 02:47:58 -04:00
|
|
|
blt::gfx::first_person_camera_2d camera;
|
|
|
|
blt::u64 lastTime;
|
|
|
|
double ft = 0;
|
|
|
|
|
|
|
|
namespace im = ImGui;
|
|
|
|
|
2024-05-02 00:32:58 -04:00
|
|
|
engine_t engine;
|
2024-04-26 18:05:00 -04:00
|
|
|
|
2024-04-30 02:47:58 -04:00
|
|
|
void init(const blt::gfx::window_data& data)
|
2024-04-11 20:40:12 -04:00
|
|
|
{
|
|
|
|
using namespace blt::gfx;
|
2024-05-02 00:32:58 -04:00
|
|
|
resources.setPrefixDirectory("../");
|
2024-05-04 03:15:58 -04:00
|
|
|
|
2024-04-26 18:05:00 -04:00
|
|
|
resources.enqueue("res/debian.png", "debian");
|
|
|
|
resources.enqueue("res/parker.png", "parker");
|
2024-05-02 00:32:58 -04:00
|
|
|
resources.enqueue("res/parkerpoint.png", "parker_point");
|
2024-04-26 18:05:00 -04:00
|
|
|
resources.enqueue("res/parker cat ears.jpg", "parkercat");
|
2024-05-04 03:15:58 -04:00
|
|
|
|
2024-04-11 20:40:12 -04:00
|
|
|
global_matrices.create_internals();
|
|
|
|
resources.load_resources();
|
|
|
|
renderer_2d.create();
|
2024-05-04 03:15:58 -04:00
|
|
|
|
2024-05-02 00:32:58 -04:00
|
|
|
engine.init(data);
|
2024-05-04 03:15:58 -04:00
|
|
|
|
2024-04-30 02:47:58 -04:00
|
|
|
lastTime = blt::system::nanoTime();
|
2024-04-11 20:40:12 -04:00
|
|
|
}
|
|
|
|
|
2024-04-30 02:47:58 -04:00
|
|
|
void update(const blt::gfx::window_data& data)
|
2024-04-11 20:40:12 -04:00
|
|
|
{
|
2024-04-30 02:47:58 -04:00
|
|
|
global_matrices.update_perspectives(data.width, data.height, 90, 0.1, 2000);
|
2024-05-04 03:15:58 -04:00
|
|
|
|
2024-04-30 02:47:58 -04:00
|
|
|
//im::ShowDemoWindow();
|
2024-05-04 03:15:58 -04:00
|
|
|
|
2024-05-02 00:32:58 -04:00
|
|
|
engine.render(data, ft);
|
2024-05-04 03:15:58 -04:00
|
|
|
|
2024-04-11 20:40:12 -04:00
|
|
|
camera.update();
|
|
|
|
camera.update_view(global_matrices);
|
|
|
|
global_matrices.update();
|
2024-05-04 03:15:58 -04:00
|
|
|
|
|
|
|
renderer_2d.render(data.width, data.height);
|
|
|
|
|
2024-05-03 02:46:02 -04:00
|
|
|
const auto currentTime = blt::system::nanoTime();
|
|
|
|
const auto diff = currentTime - lastTime;
|
2024-04-30 02:47:58 -04:00
|
|
|
lastTime = currentTime;
|
|
|
|
ft = static_cast<double>(diff) / 1000000000.0;
|
2024-04-11 20:40:12 -04:00
|
|
|
}
|
|
|
|
|
2024-04-30 02:47:58 -04:00
|
|
|
int main(int, const char**)
|
2024-04-11 20:40:12 -04:00
|
|
|
{
|
2024-05-14 02:58:25 -04:00
|
|
|
blt::gfx::init(blt::gfx::window_data{"Force-Directed Graph Drawing", init, update, 1440, 720}.setSyncInterval(1));
|
2024-04-11 20:40:12 -04:00
|
|
|
global_matrices.cleanup();
|
|
|
|
resources.cleanup();
|
|
|
|
renderer_2d.cleanup();
|
|
|
|
blt::gfx::cleanup();
|
2024-05-04 03:15:58 -04:00
|
|
|
|
2024-04-26 01:11:24 -04:00
|
|
|
return 0;
|
2024-04-11 20:40:12 -04:00
|
|
|
}
|