2023-11-28 01:56:10 -05:00
|
|
|
#include <blt/gfx/window.h>
|
2023-12-28 16:14:12 -05:00
|
|
|
#include <blt/gfx/shader.h>
|
2023-12-29 18:38:07 -05:00
|
|
|
#include <blt/gfx/state.h>
|
2023-12-28 16:14:12 -05:00
|
|
|
#include <blt/std/logging.h>
|
2023-12-16 01:32:25 -05:00
|
|
|
#include <imgui.h>
|
2023-12-26 21:14:01 -05:00
|
|
|
#include "blt/gfx/imgui/IconsFontAwesome5.h"
|
2023-11-28 01:56:10 -05:00
|
|
|
|
2024-01-01 22:15:30 -05:00
|
|
|
#include "blt/gfx/renderer/resource_manager.h"
|
2024-01-02 02:38:56 -05:00
|
|
|
#include "blt/gfx/renderer/batch_2d_renderer.h"
|
2024-01-02 14:20:34 -05:00
|
|
|
#include "blt/gfx/renderer/camera.h"
|
2023-12-28 16:14:12 -05:00
|
|
|
|
2023-12-29 18:38:07 -05:00
|
|
|
|
|
|
|
blt::gfx::matrix_state_manager global_matrices;
|
2024-01-01 22:15:30 -05:00
|
|
|
blt::gfx::resource_manager resources;
|
2024-01-02 02:38:56 -05:00
|
|
|
blt::gfx::batch_renderer_2d renderer_2d(resources);
|
2024-01-02 14:20:34 -05:00
|
|
|
blt::gfx::first_person_camera camera;
|
2023-12-29 18:38:07 -05:00
|
|
|
float x = 0, y = 0, z = 0;
|
2023-12-29 19:25:41 -05:00
|
|
|
float bx = 500, by = 500;
|
|
|
|
float mx = 0, my = -9.8;
|
2023-12-29 18:38:07 -05:00
|
|
|
|
2023-11-28 01:56:10 -05:00
|
|
|
void init()
|
|
|
|
{
|
2023-12-28 16:14:12 -05:00
|
|
|
using namespace blt::gfx;
|
|
|
|
|
2024-01-01 22:15:30 -05:00
|
|
|
resources.enqueue("../resources/textures/cumdollar.jpg", "ibuythat");
|
|
|
|
resources.enqueue("../resources/textures/dfoedbi-28157978-1555-45c3-b2f4-d5e5fe25b253.png", "niko");
|
2023-12-29 19:25:41 -05:00
|
|
|
|
2023-12-29 18:38:07 -05:00
|
|
|
global_matrices.create_internals();
|
2024-01-01 22:15:30 -05:00
|
|
|
resources.load_resources();
|
2024-01-02 02:38:56 -05:00
|
|
|
renderer_2d.create();
|
2023-11-28 01:56:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void update(std::int32_t width, std::int32_t height)
|
|
|
|
{
|
2024-01-02 14:20:34 -05:00
|
|
|
global_matrices.update_perspectives(width, height, 90, 0.1, 2000);
|
2023-12-16 03:19:27 -05:00
|
|
|
ImGui::ShowDemoWindow();
|
2024-01-02 14:20:34 -05:00
|
|
|
ImGui::SetNextWindowSize(ImVec2(200, 100));
|
2023-12-29 18:38:07 -05:00
|
|
|
ImGui::Begin("Debug Info Panel", nullptr, ImGuiWindowFlags_NoResize);
|
|
|
|
ImGui::Text("%s FPS: %f", ICON_FA_WRENCH, 1.0e9 / static_cast<double>(blt::gfx::getFrameDelta()));
|
2024-01-02 02:38:56 -05:00
|
|
|
ImGui::Text("Draw Count: %zu", renderer_2d.draw_count());
|
2024-01-02 14:20:34 -05:00
|
|
|
ImGui::Text("Position: %f %f %f", camera.position().x(), camera.position().y(), camera.position().z());
|
2023-12-26 21:14:01 -05:00
|
|
|
ImGui::End();
|
2023-12-28 16:14:12 -05:00
|
|
|
|
2024-01-02 14:20:34 -05:00
|
|
|
camera.update();
|
|
|
|
camera.update_view(global_matrices);
|
2023-12-29 18:38:07 -05:00
|
|
|
|
|
|
|
global_matrices.update();
|
2023-12-28 16:14:12 -05:00
|
|
|
|
2023-12-29 19:25:41 -05:00
|
|
|
const float w = 120, h = 120, cf = 30, rf = 15, crf = 10;
|
2023-12-28 16:14:12 -05:00
|
|
|
|
2024-01-02 13:03:51 -05:00
|
|
|
renderer_2d.drawRectangle("ibuythat", (float)width/2.0f, (float)height/2.0f, (float)width, (float)height, 90.0f);
|
|
|
|
renderer_2d.drawRectangle("niko", bx, by, w, h);
|
2023-12-28 16:14:12 -05:00
|
|
|
|
2023-12-29 19:25:41 -05:00
|
|
|
bx += mx * blt::gfx::getFrameDeltaSeconds() * cf;
|
|
|
|
by += my * blt::gfx::getFrameDeltaSeconds() * cf;
|
|
|
|
|
|
|
|
if (bx < w / 2.0 || bx > width - w / 2.0)
|
|
|
|
{
|
|
|
|
mx = -mx;
|
|
|
|
my += (static_cast<float>(rand()) / static_cast<float>(RAND_MAX) * rf + crf) - (rf + crf) / 2.0f;
|
|
|
|
}
|
|
|
|
if (by < h / 2.0 || by > height - h / 2.0)
|
|
|
|
{
|
|
|
|
my = -my;
|
|
|
|
mx += (static_cast<float>(rand()) / static_cast<float>(RAND_MAX) * rf + crf) - (rf + crf) / 2.0f;
|
|
|
|
}
|
|
|
|
if (mx > 100 || mx < -100)
|
|
|
|
{
|
|
|
|
mx = mx * 0.2;
|
|
|
|
}
|
|
|
|
if (my > 100 || my < -100)
|
|
|
|
my = my * 0.2;
|
2024-01-02 02:38:56 -05:00
|
|
|
|
|
|
|
renderer_2d.render();
|
2023-11-28 01:56:10 -05:00
|
|
|
}
|
|
|
|
|
2023-11-27 23:53:20 -05:00
|
|
|
int main()
|
|
|
|
{
|
2023-11-28 01:56:10 -05:00
|
|
|
blt::gfx::init(blt::gfx::window_data{"My Sexy Window", init, update}.setSyncInterval(1));
|
2023-12-29 18:38:07 -05:00
|
|
|
global_matrices.cleanup();
|
2024-01-01 22:15:30 -05:00
|
|
|
resources.cleanup();
|
2024-01-02 02:38:56 -05:00
|
|
|
renderer_2d.cleanup();
|
2023-11-28 01:56:10 -05:00
|
|
|
blt::gfx::cleanup();
|
2023-11-27 23:53:20 -05:00
|
|
|
return 0;
|
|
|
|
}
|