首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >窗口未在nuklear简单示例中显示

窗口未在nuklear简单示例中显示
EN

Stack Overflow用户
提问于 2020-01-17 04:47:00
回答 1查看 270关注 0票数 0

嗨,我写了这个简单的例子与nuklear图形用户界面工具包,但窗口不显示?我做什么好?

代码语言:javascript
复制
#define NK_IMPLEMENTATION
#define NK_INCLUDE_DEFAULT_ALLOCATOR
#define NK_INCLUDE_FONT_BAKING
#define NK_INCLUDE_STANDARD_IO
#include <nuklear.h>

int main(int argc, char **argv) {
    struct nk_font_atlas font_atlas;
    nk_font_atlas_init_default(&font_atlas);
    nk_font_atlas_begin(&font_atlas);

    int img_width, img_height;
    // struct nk_font_config font_config;
    const char *font_path = "/home/.../font/file.ttf";
    struct nk_font *font = nk_font_atlas_add_from_file(&font_atlas, font_path, 13, NULL);
    const void* img = nk_font_atlas_bake(&font_atlas, &img_width, &img_height, NK_FONT_ATLAS_RGBA32);

    // char *img_two[img_width * img_height];
    // memcpy(img_two, img, img_width * img_height);
    nk_font_atlas_end(&font_atlas, nk_handle_id(0), NULL);

    int running = 1;
    struct nk_context ctx;
    nk_init_default(&ctx, &font->handle);

    enum {EASY, HARD};
    static int op = EASY;
    static float value = 0.6f;
    static int i =  20;

    while (running) {
        struct nk_rect window_bound = { 50, 50, 220, 220 };
        nk_flags window_flag = NK_WINDOW_BORDER | NK_WINDOW_MOVABLE | NK_WINDOW_CLOSABLE;
        int window_status = nk_begin(&ctx, "show", window_bound, window_flag);
        if (window_status) {
            nk_layout_row_static(&ctx, 30, 80, 1);
            if (nk_button_label(&ctx, "button")) {
                /* event handling */
            }

            /* fixed widget window ratio width */
            nk_layout_row_dynamic(&ctx, 30, 2);
            if (nk_option_label(&ctx, "easy", op == EASY)) op = EASY;
            if (nk_option_label(&ctx, "hard", op == HARD)) op = HARD;

            /* custom widget pixel width */
            nk_layout_row_begin(&ctx, NK_STATIC, 30, 2);

            {
                nk_layout_row_push(&ctx, 50);
                nk_label(&ctx, "Volume:", NK_TEXT_LEFT);
                nk_layout_row_push(&ctx, 110);
                nk_slider_float(&ctx, 0, &value, 1.0f, 0.1f);
            }

            nk_layout_row_end(&ctx);
        }

        nk_end(&ctx);
        nk_clear(&ctx);
    }

    nk_font_atlas_clear(&font_atlas);
    nk_free(&ctx);
    return 0;
}
EN

回答 1

Stack Overflow用户

发布于 2020-01-21 06:08:22

问题是Nuklear本身不能做太多事情。你需要使用一些渲染API来实际绘制你的窗口,比如SDL、OpenGL、DirectX或者其他的东西。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59777588

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档