Skip to content

[Question] Nothing Shows Up in Project Using SDL3 + bgfx + zgui #50

@Logickin-Lambda

Description

@Logickin-Lambda

This is the second part of this issue, but it has no relation to the previous issues nor it has any bug, but it is a question about setting up the project.

As previously mentioned:
I was trying to replicate the original bgfx hello world example in windows 11, involving bgfx, sdl3, and imgui (linked with the zig equivalence). So far the logo, the text and the backend are properly loaded, but I have been struggling on loading zgui component into the project.

Initially, I have import the dependency with .sdl3_gpu as shown:

 // The main objective of this project, loading imgui const zgui = b.dependency("zgui", .{ .shared = false, .optimize = optimize, .backend = .sdl3_gpu, }); exe_mod.addImport("zgui", zgui.module("root")); exe.linkLibrary(zgui.artifact("imgui")); 

In the main function of the program, I have used the following code to initialize zgui, where MAIN_FONT is an embed file of the Roboto font:

 const smp = std.heap.smp_allocator; zgui.init(smp); defer zgui.deinit(); var main_config = zgui.FontConfig.init(); main_config.font_data_owned_by_atlas = false; _ = zgui.io.addFontFromMemoryWithConfig(MAIN_FONT, 16, main_config, null); 

Since I have picked the backend as sdl_gpu, the init function requires me to provide ImGui_ImplSDLGPU3_InitInfo before drawing anything onto the screen, so I have manually create two structs to comply the requires as shown:

 const sdl_gpu_device = c.SDL_CreateGPUDevice(c.SDL_GPU_SHADERFORMAT_SPIRV, true, "vulkan") orelse { @panic("Cannot Create SDL_GPU_DEVICE"); }; const imgui_init_info = zgui.backend.ImGui_ImplSDLGPU3_InitInfo{ .device = sdl_gpu_device, .color_target_format = c.SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UINT, .msaa_samples = 1, }; std.debug.print("Initializing Imgui Backend...\n", .{}); zgui.backend.init(window, imgui_init_info); defer zgui.backend.deinit(); 

In the main event loop, I tried to create a popup based on the simple example, thus the following code for imgui:

 // imgui components std.debug.print("Loading Imgui Components...\n", .{}); zgui.backend.newFrame(window_config.width, window_config.height, 1); // SDL has Scale parameter zgui.setNextWindowPos(.{ .x = 20, .y = 20, .cond = .first_use_ever }); zgui.setNextWindowSize(.{ .w = -1, .h = -1, .cond = .first_use_ever }); if (zgui.begin("My window", .{})) { if (zgui.button("Press me!", .{ .w = 200 })) { std.debug.print("Button pressed\n", .{}); } } zgui.end(); zgui.endFrame(); 

From here, after I have run the example, I don't get the imgui component on the screen:
Image

Clearly, it must be a user error from my end, but since I am new to these libraries, I don't really know which part of my code has gone wrong. I wish to know if anyone have similar project set up and could share about your experience on working with these libraries such that I can narrow down and even find the issue.

Let me know if you want more information about the issue, and just in case if you want to look into my actual code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions