Crafter.Graphics/examples/VulkanTriangle/main.cpp

35 lines
1 KiB
C++
Raw Normal View History

2025-06-13 23:59:36 +02:00
#include <vulkan/vulkan.h>
import Crafter.Graphics;
using namespace Crafter;
2026-01-28 01:06:48 +01:00
import std;
2025-06-13 23:59:36 +02:00
int main() {
/*
2026-01-28 01:06:48 +01:00
This sets up all necessary things and creates the vulkan device.
This must be called before any vulkan related things.
Things like VkDevice are static members of the VulkanDevice class.
2025-06-13 23:59:36 +02:00
*/
2026-01-28 01:06:48 +01:00
VulkanDevice::CreateDevice();
WindowVulkan window(1280, 720, "HelloVulkan");
2025-06-13 23:59:36 +02:00
/*
2026-01-28 01:06:48 +01:00
StartInit gives you a VkCommandBuffer to use before the event loop starts
Use this for inititializing things like textures.
2025-06-13 23:59:36 +02:00
*/
2026-01-28 01:06:48 +01:00
VkCommandBuffer cmd = window.StartInit();
2025-06-13 23:59:36 +02:00
2026-01-28 01:06:48 +01:00
Mesh triangle;
std::array<Vertex, 3> verts {{{-0.1, 0, 0}, {0, 0.1, 0}, {0.1, 0, 0}}};
std::array<std::uint32_t, 3> index {{0,1,2}};
triangle.Build(verts, index, cmd);
2025-06-13 23:59:36 +02:00
/*
2026-01-28 01:06:48 +01:00
FinishInit executes all commands recorded to StartInit.
This must be called before the the event loops starts if you called StartInit before.
2025-06-13 23:59:36 +02:00
*/
2026-01-28 01:06:48 +01:00
window.FinishInit();
2025-06-13 23:59:36 +02:00
2026-01-28 01:06:48 +01:00
window.Render();
2025-06-13 23:59:36 +02:00
window.StartSync();
}