vulkan-project/main.cpp
2022-10-07 23:30:44 +02:00

61 lines
2.0 KiB
C++

#include "main.hpp"
#include "vulkan_instance.hpp"
#include "renderer2D.hpp"
#include <thread>
namespace gz::vk {
int mainLoop() {
gz::SettingsManagerCreateInfo<SettingsTypes> smCI{};
smCI.filepath = gz::vk::CONFIG_FILE;
smCI.readFileOnCreation = true;
smCI.writeFileOnExit = true;
smCI.initialValues = gz::vk::INITIAL_SETTINGS;
smCI.throwExceptionWhenNewValueNotAllowed = true;
VulkanInstance vulkanInstance(smCI);
vulkanInstance.init();
Renderer2D r2D(vulkanInstance);
Rectangle rect1( 90, 91, 92, 93, { 1.0f, 0.9f, 0.8f});
Rectangle rect2(190, 191, 192, 193, { 0.7f, 0.6f, 0.5f});
Rectangle rect3(420, 64, 512, 64, { 0.0f, 1.0f, 0.0f});
Rectangle rect4( 32, 120, 400, 400, { 0.0f, 0.0f, 1.0f});
Rectangle rect5( -600, -600, 800, 400, { 1.0f, 0.0f, 0.0f});
r2D.drawShape(rect1);
r2D.drawShape(rect2);
r2D.drawShape(rect3);
r2D.drawShape(rect4);
r2D.drawShape(rect5);
r2D.fillVertexBufferWithShapes();
r2D.fillIndexBufferWithShapes();
/* gz::FontManager fm("fonts"); */
/* fm.loadFont("menu.ttf"); */
/* /1* fm.getFaces().at("menu.ttf"). *1/ */
try {
uint32_t imageIndex;
while (! glfwWindowShouldClose(vulkanInstance.window)) {
glfwPollEvents();
imageIndex = vulkanInstance.beginFrameDraw();
r2D.drawFrame(imageIndex);
vulkanInstance.endFrameDraw(imageIndex);
auto SLEEP_TIME = std::chrono::milliseconds(1000 / vulkanInstance.settings.get<uint32_t>("framerate"));
std::this_thread::sleep_for(SLEEP_TIME);
}
r2D.cleanup();
vulkanInstance.cleanup();
}
catch (const std::exception& e) {
std::cerr << e.what() << std::endl;
return 1;
}
return 0;
}
}
int main() {
return gz::vk::mainLoop();
}