This commit is contained in:
Mars 2024-10-15 19:49:39 -04:00
parent 7632347218
commit 154a81721d
Signed by untrusted user: pupbrained
GPG key ID: 874E22DF2F9DFCB5
5 changed files with 66 additions and 9 deletions

View file

@ -1,10 +1,6 @@
# This file was generated by nvfetcher, please do not modify it manually. # This file was generated by nvfetcher, please do not modify it manually.
{ fetchgit, fetchurl, fetchFromGitHub, dockerTools }:
{ {
fetchgit,
fetchurl,
fetchFromGitHub,
dockerTools,
}: {
fmt = { fmt = {
pname = "fmt"; pname = "fmt";
version = "11.0.2"; version = "11.0.2";

View file

@ -2,11 +2,11 @@
"nodes": { "nodes": {
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1728698577, "lastModified": 1729022018,
"narHash": "sha256-hdbJjMr9myxGcByVlR9zAbQsWfZwl6NKzZodmyTzACc=", "narHash": "sha256-fsZYL4ggDUvVvIcnBk16dSsSsLlg3H4cMzs26FZuqCs=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "d4c28e77c38d73b23346656c102a94d90af3cf60", "rev": "f490aba9999744d0ecb5e5594760a606de441ad6",
"type": "github" "type": "github"
}, },
"original": { "original": {

View file

@ -40,10 +40,16 @@
fmt = mkPkg "fmt"; fmt = mkPkg "fmt";
imgui = pkgs.imgui.override {
IMGUI_BUILD_GLFW_BINDING = true;
IMGUI_BUILD_VULKAN_BINDING = true;
};
deps = with pkgs; [ deps = with pkgs; [
fmt fmt
glfw glfw
glm glm
imgui
shaderc shaderc
vulkan-extension-layer vulkan-extension-layer
vulkan-memory-allocator vulkan-memory-allocator
@ -106,7 +112,7 @@
meson meson
nil nil
ninja ninja
nvfetcher #nvfetcher
pkg-config pkg-config
unzip unzip

View file

@ -29,6 +29,7 @@ deps = [
dependency('glfw3', include_type: 'system'), dependency('glfw3', include_type: 'system'),
dependency('glm', include_type: 'system'), dependency('glm', include_type: 'system'),
dependency('vulkan', include_type: 'system'), dependency('vulkan', include_type: 'system'),
cpp.find_library('imgui'),
] ]
executable( executable(

View file

@ -35,6 +35,11 @@ VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE
// Vertex class // Vertex class
#include "util/vertex.h" #include "util/vertex.h"
// ImGui
#include <imgui.h>
#include <imgui_impl_glfw.h>
#include <imgui_impl_vulkan.h>
// Use {} instead of () // Use {} instead of ()
#define VKFW_NO_STRUCT_CONSTRUCTORS #define VKFW_NO_STRUCT_CONSTRUCTORS
// GLFW C++ wrapper // GLFW C++ wrapper
@ -77,6 +82,12 @@ class VulkanApp {
initVulkan(); initVulkan();
// Render loop // Render loop
mainLoop(); mainLoop();
cleanupSwapChain();
ImGui_ImplVulkan_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
} }
private: private:
@ -239,6 +250,39 @@ class VulkanApp {
createDescriptorSets(); createDescriptorSets();
createCommandBuffers(); createCommandBuffers();
createSyncObjects(); createSyncObjects();
initImGui();
}
void initImGui() {
// Create ImGui context
IMGUI_CHECKVERSION();
ImGui::CreateContext();
// Setup Dear ImGui style
ImGui::StyleColorsDark();
// Initialize ImGui for GLFW and Vulkan
ImGui_ImplGlfw_InitForVulkan(mWindow.get(), true);
ImGui_ImplVulkan_InitInfo initInfo = {};
initInfo.Instance = mInstance.get();
initInfo.PhysicalDevice = mPhysicalDevice;
initInfo.Device = mDevice.get();
initInfo.QueueFamily = findQueueFamilies(mPhysicalDevice).graphics_family.value();
initInfo.Queue = mGraphicsQueue;
initInfo.PipelineCache = VK_NULL_HANDLE;
initInfo.DescriptorPool = mDescriptorPool.get();
initInfo.RenderPass = mRenderPass.get();
initInfo.MSAASamples = static_cast<VkSampleCountFlagBits>(mMsaaSamples);
initInfo.Allocator = nullptr;
initInfo.MinImageCount = MAX_FRAMES_IN_FLIGHT;
initInfo.ImageCount = static_cast<uint32_t>(mSwapChainImages.size());
initInfo.CheckVkResultFn = nullptr;
ImGui_ImplVulkan_Init(&initInfo);
// Upload Fonts
ImGui_ImplVulkan_CreateFontsTexture();
} }
// Main loop // Main loop
@ -1565,6 +1609,16 @@ class VulkanApp {
// Draw the indexed vertices // Draw the indexed vertices
commandBuffer.drawIndexed(static_cast<u32>(mIndices.size()), 1, 0, 0, 0); commandBuffer.drawIndexed(static_cast<u32>(mIndices.size()), 1, 0, 0, 0);
ImGui_ImplVulkan_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
// Your ImGui code here
ImGui::ShowDemoWindow();
ImGui::Render();
ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), commandBuffer);
// End the render pass // End the render pass
commandBuffer.endRenderPass(); commandBuffer.endRenderPass();