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>
|
|
|
|
#include <blt/gfx/texture.h>
|
|
|
|
#include <blt/gfx/model.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
|
|
|
|
2023-12-28 16:14:12 -05:00
|
|
|
#include <shaders/test.vert>
|
|
|
|
#include <shaders/test.frag>
|
2024-01-01 22:15:30 -05:00
|
|
|
#include "blt/gfx/renderer/resource_manager.h"
|
2023-12-28 16:14:12 -05:00
|
|
|
|
2023-12-29 18:38:07 -05:00
|
|
|
|
2023-12-28 16:14:12 -05:00
|
|
|
blt::gfx::vertex_array* vao;
|
|
|
|
blt::gfx::shader_t* shader;
|
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;
|
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
|
|
|
|
|
|
|
void handle_input()
|
|
|
|
{
|
|
|
|
using namespace blt::gfx;
|
|
|
|
float moveAtX = 0;
|
|
|
|
float moveAtZ = 0;
|
|
|
|
if (isKeyPressed(GLFW_KEY_W))
|
|
|
|
moveAtX = 1;
|
|
|
|
else if (isKeyPressed(GLFW_KEY_S))
|
|
|
|
moveAtX = -1;
|
|
|
|
else
|
|
|
|
moveAtX = 0;
|
|
|
|
if (isKeyPressed(GLFW_KEY_A))
|
|
|
|
moveAtZ = 1;
|
|
|
|
else if (isKeyPressed(GLFW_KEY_D))
|
|
|
|
moveAtZ = -1;
|
|
|
|
else
|
|
|
|
moveAtZ = 0;
|
|
|
|
const float speed = 270;
|
|
|
|
y -= static_cast<float>(moveAtX * speed * getFrameDeltaSeconds());
|
|
|
|
x += static_cast<float>(moveAtZ * speed * getFrameDeltaSeconds());
|
|
|
|
|
|
|
|
blt::mat4x4 view;
|
|
|
|
view.translate(x, y, z);
|
|
|
|
global_matrices.setView(view);
|
|
|
|
}
|
2023-12-28 16:14:12 -05:00
|
|
|
|
2023-12-29 19:25:41 -05:00
|
|
|
void draw(float x_, float y_, float width_, float height_, float rot = 0)
|
|
|
|
{
|
|
|
|
blt::mat4x4 model;
|
|
|
|
model.translate(x_, y_, 0.0f);
|
|
|
|
model.scale(width_, height_, 1);
|
|
|
|
model.rotateZ(blt::toRadians(rot));
|
|
|
|
|
|
|
|
shader->setMatrix("model", model);
|
|
|
|
|
|
|
|
vao->bind();
|
|
|
|
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
|
|
|
|
}
|
|
|
|
|
2023-11-28 01:56:10 -05:00
|
|
|
void init()
|
|
|
|
{
|
2023-12-28 16:14:12 -05:00
|
|
|
using namespace blt::gfx;
|
|
|
|
|
|
|
|
vbo_t vertices_vbo;
|
|
|
|
vbo_t indices_vbo;
|
|
|
|
|
|
|
|
vertices_vbo.create();
|
|
|
|
indices_vbo.create(GL_ELEMENT_ARRAY_BUFFER);
|
|
|
|
|
|
|
|
vertices_vbo.allocate(sizeof(vertices), vertices);
|
|
|
|
indices_vbo.allocate(sizeof(indices), indices);
|
|
|
|
|
|
|
|
vao = new vertex_array();
|
|
|
|
vao->bindVBO(vertices_vbo, 0, 3, GL_FLOAT, 5 * sizeof(float), 0);
|
|
|
|
vao->bindVBO(vertices_vbo, 1, 2, GL_FLOAT, 5 * sizeof(float), 3 * sizeof(float));
|
|
|
|
vao->bindElement(indices_vbo);
|
|
|
|
|
|
|
|
shader = new shader_t(shader_test_vert, shader_test_frag);
|
|
|
|
shader->bindAttribute(0, "vertex");
|
|
|
|
shader->bindAttribute(1, "uv_in");
|
|
|
|
|
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();
|
2023-11-28 01:56:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void update(std::int32_t width, std::int32_t height)
|
|
|
|
{
|
2023-12-29 18:38:07 -05:00
|
|
|
global_matrices.update_perspectives(width, height);
|
2023-12-16 03:19:27 -05:00
|
|
|
ImGui::ShowDemoWindow();
|
2023-12-29 18:38:07 -05:00
|
|
|
ImGui::SetNextWindowSize(ImVec2(150, 65));
|
|
|
|
ImGui::Begin("Debug Info Panel", nullptr, ImGuiWindowFlags_NoResize);
|
|
|
|
ImGui::Text("%s FPS: %f", ICON_FA_WRENCH, 1.0e9 / static_cast<double>(blt::gfx::getFrameDelta()));
|
2023-12-26 21:14:01 -05:00
|
|
|
ImGui::End();
|
2023-12-28 16:14:12 -05:00
|
|
|
|
2023-12-29 18:38:07 -05:00
|
|
|
handle_input();
|
|
|
|
|
|
|
|
global_matrices.update();
|
2023-12-28 16:14:12 -05:00
|
|
|
|
|
|
|
shader->bind();
|
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
|
|
|
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
2024-01-01 22:15:30 -05:00
|
|
|
resources.get("ibuythat")->bind();
|
2023-12-29 19:25:41 -05:00
|
|
|
draw(width / 2.0, height / 2.0, width, height, 90);
|
|
|
|
|
2024-01-01 22:15:30 -05:00
|
|
|
resources.get("niko")->bind();
|
2023-12-29 19:25:41 -05:00
|
|
|
draw(bx, by, w, h, 0);
|
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;
|
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-28 16:14:12 -05:00
|
|
|
delete vao;
|
|
|
|
delete shader;
|
2023-12-29 18:38:07 -05:00
|
|
|
global_matrices.cleanup();
|
2024-01-01 22:15:30 -05:00
|
|
|
resources.cleanup();
|
2023-11-28 01:56:10 -05:00
|
|
|
blt::gfx::cleanup();
|
2023-11-27 23:53:20 -05:00
|
|
|
return 0;
|
|
|
|
}
|