#include #include #include #include #include #include #include #include "blt/gfx/imgui/IconsFontAwesome5.h" #include #include const float raw_vertices[18] = { // first triangle 0.5f, 0.5f, 0.0f, // top right 0.5f, -0.5f, 0.0f, // bottom right -0.5f, 0.5f, 0.0f, // top left // second triangle 0.5f, -0.5f, 0.0f, // bottom right -0.5f, -0.5f, 0.0f, // bottom left -0.5f, 0.5f, 0.0f // top left }; float vertices[20] = { // positions // texture coords 0.5f, 0.5f, 0.0f, 1.0f, 1.0f, // top right 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, // bottom right -0.5f, -0.5f, 0.0f, 0.0f, 0.0f, // bottom left -0.5f, 0.5f, 0.0f, 0.0f, 1.0f // top left }; const unsigned int indices[6] = { // note that we start from 0! 0, 1, 3, // first triangle 1, 2, 3 // second triangle }; blt::gfx::vertex_array* vao; blt::gfx::shader_t* shader; blt::gfx::texture_gl2D* texture; blt::gfx::matrix_state_manager global_matrices; float x = 0, y = 0, z = 0; 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(moveAtX * speed * getFrameDeltaSeconds()); x += static_cast(moveAtZ * speed * getFrameDeltaSeconds()); blt::mat4x4 view; view.translate(x, y, z); global_matrices.setView(view); } void init() { 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"); texture_file file("../resources/textures/cumdollar.jpg"); texture = new texture_gl2D(file.texture()); global_matrices.create_internals(); } void update(std::int32_t width, std::int32_t height) { global_matrices.update_perspectives(width, height); ImGui::ShowDemoWindow(); 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(blt::gfx::getFrameDelta())); ImGui::End(); handle_input(); global_matrices.update(); shader->bind(); blt::mat4x4 model; model.translate((float) width / 2.0f, (float) height / 2.0f, 0.0f); model.scale(500, 500, 1); shader->setMatrix("model", model); glActiveTexture(GL_TEXTURE0); texture->bind(); vao->bind(); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); } int main() { blt::gfx::init(blt::gfx::window_data{"My Sexy Window", init, update}.setSyncInterval(1)); delete vao; delete shader; delete texture; global_matrices.cleanup(); blt::gfx::cleanup(); return 0; }