sashakddr
Topic Author
Posts: 1
Joined: 21 Dec 2024, 02:49

C++ and Vulkan invisible text

18 Jan 2025, 13:08

Hi, I'm trying to integrate NoesisGUI in my vulkan c++ project, theme (buttons style) seems to work, but the text is completely invisible, what could be the issue?

Here is how I initialize Noesis.
	Noesis::SetLogHandler(
		[](const char* file, uint32_t line, uint32_t level, const char* channel, const char* message) {
			printf("[%s:%u] %s: %s\n", file, line, channel, message);
		}
	);
	Noesis::SetErrorHandler(
		[](const char* file, uint32_t line, const char* message, bool fatal) {
		printf("[%s:%u] %s: %s\n", file, line, message, fatal ? "true" : "false");
		}
	);
	
	Noesis::GUI::Init();

	std::string currentPath = std::filesystem::current_path().string();
	std::string xamlRootPath = currentPath + "/xaml";
	std::string fontsRootPath = currentPath + "/fonts";
	std::string texturesRootPath = currentPath + "/textures";

	Noesis::Ptr<NoesisApp::LocalXamlProvider> xamlProvider =
		*new NoesisApp::LocalXamlProvider(xamlRootPath.c_str());
	Noesis::Ptr<NoesisApp::LocalFontProvider> fontProvider =
		*new NoesisApp::LocalFontProvider(fontsRootPath.c_str());
	Noesis::Ptr<NoesisApp::LocalTextureProvider> textureProvider =
		*new NoesisApp::LocalTextureProvider(texturesRootPath.c_str());

	Noesis::GUI::SetXamlProvider(xamlProvider);
	Noesis::GUI::SetFontProvider(fontProvider);
	Noesis::GUI::SetTextureProvider(textureProvider);

	NoesisApp::VKFactory::InstanceInfo instanceInfo{};
	instanceInfo.instance = vkInit.instance;
	instanceInfo.physicalDevice = vkInit.physicalDevice;
	instanceInfo.device = vkInit.device;
	instanceInfo.pipelineCache = VK_NULL_HANDLE; // Optional pipeline cache
	instanceInfo.queueFamilyIndex = vkInit.queueFamilyIndices.presentFamily.value();
	instanceInfo.vkGetInstanceProcAddr = reinterpret_cast<PFN_vkGetInstanceProcAddr>(
		vkGetInstanceProcAddr(vkInit.instance, "vkGetInstanceProcAddr")
	);

	noesisRenderDevice = NoesisApp::VKFactory::CreateDevice(true, instanceInfo);
	if (!noesisRenderDevice) {
		throw std::runtime_error("Failed to create Noesis Vulkan render device");
	}

	NoesisApp::VKFactory::SetRenderPass(noesisRenderDevice, objectRenderPass, vkInit.colorSamples);

    Noesis::Ptr<Noesis::FrameworkElement> xamlElement = Noesis::GUI::LoadXaml
		<Noesis::FrameworkElement>(Noesis::Uri("MainMenu.xaml"));
	if (!xamlElement) {
		throw std::runtime_error("Failed to load XAML file");
	}

	noesisView = Noesis::GUI::CreateView(xamlElement);
	if (!noesisView) {
		throw std::runtime_error("Failed to create Noesis renderer");
	}

	noesisView->GetRenderer()->Init(noesisRenderDevice);
	noesisView->SetSize(swapChainExtent.width, swapChainExtent.height);
Buffer recording
VkCommandBufferBeginInfo beginInfo{};
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;

if (vkBeginCommandBuffer(commandBuffer, &beginInfo) != VK_SUCCESS) {
	throw std::runtime_error("failed to begin recording command buffer!");
}

VkRenderPassBeginInfo renderPassInfo{};
renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
renderPassInfo.renderPass = objectRenderPass;
renderPassInfo.framebuffer = swapChainFramebuffers[imageIndex];
renderPassInfo.renderArea.offset = { 0, 0 };
renderPassInfo.renderArea.extent = swapChainExtent;

std::array<VkClearValue, 2> clearValues{};
clearValues[0].color = { {0.0f, 0.0f, 0.0f, 1.0f} };
clearValues[1].depthStencil = { 1.0f, 0 };

renderPassInfo.clearValueCount = static_cast<uint32_t>(clearValues.size());
renderPassInfo.pClearValues = clearValues.data();

VkRenderPassBeginInfo noesisRenderPassInfo = {};
noesisRenderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
noesisRenderPassInfo.renderPass = objectRenderPass;
noesisRenderPassInfo.framebuffer = swapChainFramebuffers[imageIndex];
noesisRenderPassInfo.renderArea.offset = { 0, 0 };
noesisRenderPassInfo.renderArea.extent = swapChainExtent;
noesisRenderPassInfo.clearValueCount = static_cast<uint32_t>(clearValues.size());
noesisRenderPassInfo.pClearValues = clearValues.data();

vkCmdBeginRenderPass(commandBuffer, &noesisRenderPassInfo, VK_SUBPASS_CONTENTS_INLINE);

vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines["object"]);
NoesisApp::VKFactory::RecordingInfo recordingInfo{};
recordingInfo.commandBuffer = commandBuffers[currentFrame];
NoesisApp::VKFactory::SetCommandBuffer(noesisRenderDevice, recordingInfo);
	
noesisView->Update(timeSinceLaunch);
//noesisRenderDevice->BeginOnscreenRender();
noesisView->GetRenderer()->UpdateRenderTree();
noesisView->GetRenderer()->RenderOffscreen();
noesisView->GetRenderer()->Render();
//noesisRenderDevice->EndOnscreenRender();

vkCmdEndRenderPass(commandBuffer);

if (vkEndCommandBuffer(commandBuffer) != VK_SUCCESS) {
	throw std::runtime_error("failed to record command buffer!");
}
Vertex shader
#version 450

layout(location = 0) in vec3 inPosition;
layout(location = 1) in vec3 inNormal;
layout(location = 2) in vec3 inColor;
layout(location = 3) in vec2 inTexCoord0;
layout(location = 4) in vec2 inTexCoord1;
layout(location = 5) in ivec4 inBoneIDs;
layout(location = 6) in vec4 inBoneWeights;

layout(location = 0) out vec3 outPosition;
layout(location = 1) out vec3 outColor;
layout(location = 2) out vec2 outTexCoord0; 

void main() 
{
	outTexCoord0 = inTexCoord0;
	outColor = inColor;
	gl_Position = vec4(inPosition, 1.0);
}
Fragment shader
#version 450

layout(location = 0) in vec3 inPosition;
layout(location = 1) in vec3 inColor;
layout(location = 2) in vec2 inTexCoord0;

layout(location = 0) out vec4 outColor;

void main() 
{
	outColor = vec4(inColor, 1.0);
}
MainMenu.xaml
<Grid
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <StackPanel VerticalAlignment="Center" Width="200" TextElement.FontSize="25">
      <TextBlock Text="Foreground" FontFamily="../fonts/#LCDMono2" TextAlignment="Center" Margin="4" Foreground="#FF3298B5"/>
      <TextBlock Text="Background" FontFamily="../fonts/#LCDMono2" TextAlignment="Center" Margin="3" Padding="1" Background="#FF11FF00" Foreground="#FFFFFFFF"/>
    </StackPanel>
</Grid>
Command line output
[..\..\..\..\NoesisSDK\Native\Src\Packages\Gui\Core\Src\UI.cpp:848] : 'MainMenu.xaml' loaded
[..\..\..\..\NoesisSDK\Native\Src\Packages\Drawing\VGL\Src\VGLFontFace.cpp:71] : '../fonts/#LCDMono2' loaded
 
User avatar
jsantos
Site Admin
Posts: 4822
Joined: 20 Jan 2012, 17:18
Contact:

Re: C++ and Vulkan invisible text

20 Jan 2025, 12:58

I only see one fragment shader; you'll also need one for the text. Please refer to our reference implementation. I also recommend using RenderDoc to capture frames and compare what our implementation is doing with what yours is rendering

Who is online

Users browsing this forum: Bing [Bot] and 4 guests