项目地址:
https://github.com/vurtun/nuklear
源码只有一个 nuklear.h 文件, 约2.5万行代码
https://github.com/vurtun/nuklear/blob/master/nuklear.h
离线
这个看来很不错哦,
试一试编译一个demo.
sudo apt-get install libglew-dev
sudo apt-get install libglfw3-dev
发现ubuntu14.04 不能安装 libglfw3-dev
hexing@ubuntu:/disk2/licheepi/u-boot$ sudo apt-get install libglfw3-dev
[sudo] password for hexing:
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package libglfw3-dev
看来只能下载源码自己编译安装了。
在线
在线
yunge@ubuntu:/tmp/nuklear/example$ make
cc -std=c99 -pedantic -O2 -o bin/file_browser file_browser.c -L/usr/local/lib -lglfw3 -lGL -lm -lGLU -lGLEW
/usr/bin/ld: /usr/local/lib/libglfw3.a(x11_window.c.o): undefined reference to symbol 'XConvertSelection'
//usr/lib/x86_64-linux-gnu/libX11.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make: *** [file_browser] Error 1
真是个悲剧,链接错误, 找不到XConvertSelection函数。
在线
放狗一搜,找个一个链接: undefined-references-compiling-opengl-glfw-glew-on-ubuntu
第15行改成:
LIBS := $(GLFW3) -lGL -lm -lGLU -lGLEW -lGLEW -lglfw3 -lGL -lX11 -lXi -lXrandr -lXxf86vm -lXinerama -lXcursor -lrt -lm -pthread -ldl
搞定编译:
yunge@ubuntu:/tmp/nuklear/example$ make
cc -std=c99 -pedantic -O2 -o bin/file_browser file_browser.c -L/usr/local/lib -lglfw3 -lGL -lm -lGLU -lGLEW -lGLEW -lglfw3 -lGL -lX11 -lXi -lXrandr -lXxf86vm -lXinerama -lXcursor -lrt -lm -pthread -ldl
cc -std=c99 -pedantic -O2 -o bin/extended extended.c -L/usr/local/lib -lglfw3 -lGL -lm -lGLU -lGLEW -lGLEW -lglfw3 -lGL -lX11 -lXi -lXrandr -lXxf86vm -lXinerama -lXcursor -lrt -lm -pthread -ldl
cc -std=c99 -pedantic -O2 -o bin/canvas canvas.c -L/usr/local/lib -lglfw3 -lGL -lm -lGLU -lGLEW -lGLEW -lglfw3 -lGL -lX11 -lXi -lXrandr -lXxf86vm -lXinerama -lXcursor -lrt -lm -pthread -ldl
cc -std=c99 -pedantic -O2 -o bin/skinning skinning.c -L/usr/local/lib -lglfw3 -lGL -lm -lGLU -lGLEW -lGLEW -lglfw3 -lGL -lX11 -lXi -lXrandr -lXxf86vm -lXinerama -lXcursor -lrt -lm -pthread -ldl
在线
yunge@ubuntu:/disk2/nuklear/example$ bin/canvas
Error 65543: GLX: Failed to create context: GLXBadFBConfig
canvas: /tmp/glfw/src/window.c:944: glfwSetWindowUserPointer: Assertion `window != ((void *)0)' failed.
Aborted (core dumped)
yunge@ubuntu:/disk2/nuklear/example$ bin/extended
Error 65543: GLX: Failed to create context: GLXBadFBConfig
extended: /tmp/glfw/src/window.c:944: glfwSetWindowUserPointer: Assertion `window != ((void *)0)' failed.
Aborted (core dumped)
yunge@ubuntu:/disk2/nuklear/example$ bin/
canvas extended file_browser skinning
yunge@ubuntu:/disk2/nuklear/example$ bin/skinning
Error 65543: GLX: Failed to create context: GLXBadFBConfig
skinning: /tmp/glfw/src/window.c:944: glfwSetWindowUserPointer: Assertion `window != ((void *)0)' failed.
Aborted (core dumped)
yunge@ubuntu:/disk2/nuklear/example$ bin/file_browser
Error 65543: GLX: Failed to create context: GLXBadFBConfig
file_browser: /tmp/glfw/src/window.c:944: glfwSetWindowUserPointer: Assertion `window != ((void *)0)' failed.
Aborted (core dumped)
运行悲剧了. 出现一个断言错误。接着debug
在线
sudo apt-get install mesa-utils
example$ glxinfo | grep 'version'
server glx version string: 1.4
client glx version string: 1.4
GLX version: 1.4
OpenGL version string: 2.1 Mesa 11.0.2
OpenGL shading language version string: 1.20
发现一个同病相怜的人: https://github.com/vurtun/nuklear/issues/364
在线
柳暗花明又一村,终于找到解决方案了: https://github.com/skeeto/opengl-demo
如果您的GPU不支持OpenGL 3.3并且您使用Mesa 10.0+,则可以使用环境变量强制渲染软件 LIBGL_ALWAYS_SOFTWARE=1。
把环境变量强制加上,终于搞定这个棘手的问题:
yunge@ubuntu:/tmp/nuklear/example/bin$ LIBGL_ALWAYS_SOFTWARE=1 ./extended
piemenu selected: 4
pushed!
piemenu selected: 4
piemenu selected: 4
piemenu selected: 4
有图有真相:
在线
https://github.com/skeeto/opengl-demo
这个作者建议换掉 glfw3, 改用sdl
备择方案
gl3w的一个很好的选择是glLoadGen,它几乎可以直接丢弃。GLEW既大得多,也不支持核心配置文件或一般3.2+,所以它不是现代OpenGL的选项。
对于GLFW来说,一个合理的替代方法是SDL 2.0,它更大,并且带来更多的功能,例如音频,线程和字体渲染,如果您需要它的话。
littlevgl PC上用的方案就是SDL.
在线
新建VC2013工程, 在main.c 里面把几个demo开关全部开启
#define [ins]INCLUDE_ALL[/ins]
会出现一个一个编译错误:
错误 22 error LNK2019: 无法解析的外部符号 _snprintf,该符号在函数 _calculator 中被引用C:\projects\nuklear\demo\gdi\main.obj gdi
解决方法:
修改calculator.c
snprintf() 改为 ==> _snprintf()
在线
编译glfw3 demo:
glfw_opengl3$ make
rm -f bin/demo
cc main.c -std=c99 -pedantic -O2 -o bin/demo -L/usr/local/lib -lglfw3 -lGL -lm -lGLU -lGLEW
/usr/bin/ld: /usr/local/lib/libglfw3.a(x11_window.c.o): undefined reference to symbol 'XConvertSelection'
//usr/lib/x86_64-linux-gnu/libX11.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make: *** [demo] Error 1
glfw_opengl3 出现链接错误, 修改方法和5楼一样:
# Install
BIN = demo# Flags
CFLAGS += -std=c99 -pedantic -O2SRC = main.c
OBJ = $(SRC:.c=.o)ifeq ($(OS),Windows_NT)
BIN := $(BIN).exe
LIBS = -lglfw3 -lopengl32 -lm -lGLU32 -lGLEW32
else
UNAME_S := $(shell uname -s)
GLFW3 := $(shell pkg-config --libs glfw3)
ifeq ($(UNAME_S),Darwin)
LIBS := $(GLFW3) -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo -lm -lGLEW -L/usr/local/lib
else
LIBS = $(GLFW3) -lGL -lm -lGLU -lGLEW -lGLEW -lglfw3 -lGL -lX11 -lXi -lXrandr -lXxf86vm -lXinerama -lXcursor -lrt -lm -pthread -ldl
endif
endif$(BIN):
@mkdir -p bin
rm -f bin/$(BIN) $(OBJS)
$(CC) $(SRC) $(CFLAGS) -o bin/$(BIN) $(LIBS)
运行方法和前面一样
glfw_opengl3$ bin/demo
Error 65543: GLX: Failed to create context: GLXBadFBConfig
demo: /tmp/glfw/src/window.c:539: glfwGetWindowSize: Assertion `window != ((void *)0)' failed.
Aborted (core dumped)
glfw_opengl3$
glfw_opengl3$ LIBGL_ALWAYS_SOFTWARE=1 bin/demo
在线
/* nuklear - 1.32.0 - public domain */
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdarg.h>
#include <string.h>
#include <math.h>
#include <assert.h>
#include <math.h>
#include <limits.h>
#include <time.h>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#define NK_INCLUDE_FIXED_TYPES
#define NK_INCLUDE_STANDARD_IO
#define NK_INCLUDE_STANDARD_VARARGS
#define NK_INCLUDE_DEFAULT_ALLOCATOR
#define NK_INCLUDE_VERTEX_BUFFER_OUTPUT
#define NK_INCLUDE_FONT_BAKING
#define NK_INCLUDE_DEFAULT_FONT
#define NK_IMPLEMENTATION
#define NK_GLFW_GL3_IMPLEMENTATION
#include "../../nuklear.h"
#include "nuklear_glfw_gl3.h"
#define WINDOW_WIDTH 1200
#define WINDOW_HEIGHT 800
#define MAX_VERTEX_BUFFER 512 * 1024
#define MAX_ELEMENT_BUFFER 128 * 1024
/* ===============================================================
*
* EXAMPLE
*
* ===============================================================*/
/* This are some code examples to provide a small overview of what can be
* done with this library. To try out an example uncomment the defines */
/*#define INCLUDE_ALL */
/*#define INCLUDE_STYLE */
/*#define INCLUDE_CALCULATOR */
/*#define INCLUDE_OVERVIEW */
/*#define INCLUDE_NODE_EDITOR */
#ifdef INCLUDE_ALL
#define INCLUDE_STYLE
#define INCLUDE_CALCULATOR
#define INCLUDE_OVERVIEW
#define INCLUDE_NODE_EDITOR
#endif
#ifdef INCLUDE_STYLE
#include "../style.c"
#endif
#ifdef INCLUDE_CALCULATOR
#include "../calculator.c"
#endif
#ifdef INCLUDE_OVERVIEW
#include "../overview.c"
#endif
#ifdef INCLUDE_NODE_EDITOR
#include "../node_editor.c"
#endif
/* ===============================================================
*
* DEMO
*
* ===============================================================*/
static void error_callback(int e, const char *d)
{printf("Error %d: %s\n", e, d);}
int main(void)
{
/* Platform */
static GLFWwindow *win;
int width = 0, height = 0;
struct nk_context *ctx;
struct nk_colorf bg;
/* GLFW */
glfwSetErrorCallback(error_callback);
if (!glfwInit()) {
fprintf(stdout, "[GFLW] failed to init!\n");
exit(1);
}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#ifdef __APPLE__
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
#endif
win = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Demo", NULL, NULL);
glfwMakeContextCurrent(win);
glfwGetWindowSize(win, &width, &height);
/* OpenGL */
glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
glewExperimental = 1;
if (glewInit() != GLEW_OK) {
fprintf(stderr, "Failed to setup GLEW\n");
exit(1);
}
ctx = nk_glfw3_init(win, NK_GLFW3_INSTALL_CALLBACKS);
/* Load Fonts: if none of these are loaded a default font will be used */
/* Load Cursor: if you uncomment cursor loading please hide the cursor */
{struct nk_font_atlas *atlas;
nk_glfw3_font_stash_begin(&atlas);
struct nk_font_config cfg = nk_font_config(22);
//cfg.merge_mode = nk_true;
cfg.range = nk_font_chinese_glyph_ranges();
//cfg.coord_type = NK_COORD_PIXEL;
struct nk_font *font = nk_font_atlas_add_from_file(atlas, "../../../extra_font/msyh.ttf", 13, &cfg);
nk_glfw3_font_stash_end();
nk_style_set_font(ctx, &font->handle);
}
#ifdef INCLUDE_STYLE
/*set_style(ctx, THEME_WHITE);*/
/*set_style(ctx, THEME_RED);*/
/*set_style(ctx, THEME_BLUE);*/
/*set_style(ctx, THEME_DARK);*/
#endif
bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f;
while (!glfwWindowShouldClose(win))
{
/* Input */
glfwPollEvents();
nk_glfw3_new_frame();
/* GUI */
if (nk_begin(ctx, "中文", nk_rect(50, 50, 230, 250),
NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE|
NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE))
{
enum {EASY, HARD};
static int op = EASY;
static int property = 20;
nk_layout_row_static(ctx, 30, 80, 1);
if (nk_button_label(ctx, "button"))
fprintf(stdout, "button pressed\n");
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;
nk_layout_row_dynamic(ctx, 25, 1);
nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1);
nk_layout_row_dynamic(ctx, 20, 1);
nk_label(ctx, "background:", NK_TEXT_LEFT);
nk_layout_row_dynamic(ctx, 25, 1);
if (nk_combo_begin_color(ctx, nk_rgb_cf(bg), nk_vec2(nk_widget_width(ctx),400))) {
nk_layout_row_dynamic(ctx, 120, 1);
bg = nk_color_picker(ctx, bg, NK_RGBA);
nk_layout_row_dynamic(ctx, 25, 1);
bg.r = nk_propertyf(ctx, "#R:", 0, bg.r, 1.0f, 0.01f,0.005f);
bg.g = nk_propertyf(ctx, "#G:", 0, bg.g, 1.0f, 0.01f,0.005f);
bg.b = nk_propertyf(ctx, "#B:", 0, bg.b, 1.0f, 0.01f,0.005f);
bg.a = nk_propertyf(ctx, "#A:", 0, bg.a, 1.0f, 0.01f,0.005f);
nk_combo_end(ctx);
}
}
nk_end(ctx);
/* -------------- EXAMPLES ---------------- */
#ifdef INCLUDE_CALCULATOR
calculator(ctx);
#endif
#ifdef INCLUDE_OVERVIEW
overview(ctx);
#endif
#ifdef INCLUDE_NODE_EDITOR
node_editor(ctx);
#endif
/* ----------------------------------------- */
/* Draw */
glfwGetWindowSize(win, &width, &height);
glViewport(0, 0, width, height);
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(bg.r, bg.g, bg.b, bg.a);
/* IMPORTANT: `nk_glfw_render` modifies some global OpenGL state
* with blending, scissor, face culling, depth test and viewport and
* defaults everything back into a default state.
* Make sure to either a.) save and restore or b.) reset your own state after
* rendering the UI. */
nk_glfw3_render(NK_ANTI_ALIASING_ON, MAX_VERTEX_BUFFER, MAX_ELEMENT_BUFFER);
glfwSwapBuffers(win);
}
nk_glfw3_shutdown();
glfwTerminate();
return 0;
}
修改几行代码,可以显示中文了, 但是用msyh字体只能12, 如果设置其它型号窗口就是黑的, 不知道为什么?
在线
请问一下,这个gui适合移植到单片机系统吗?
离线
测试了以下d3d11 demo,发现字体 1-19都可以运行正常, 20就不行了
/* GUI */
ctx = nk_d3d11_init(device, WINDOW_WIDTH, WINDOW_HEIGHT, MAX_VERTEX_BUFFER, MAX_INDEX_BUFFER);
/* Load Fonts: if none of these are loaded a default font will be used */
/* Load Cursor: if you uncomment cursor loading please hide the cursor */
{struct nk_font_atlas *atlas;
nk_d3d11_font_stash_begin(&atlas);
/*struct nk_font *droid = nk_font_atlas_add_from_file(atlas, "../../extra_font/DroidSans.ttf", 14, 0);*/
/*struct nk_font *robot = nk_font_atlas_add_from_file(atlas, "../../extra_font/Roboto-Regular.ttf", 14, 0);*/
/*struct nk_font *future = nk_font_atlas_add_from_file(atlas, "../../extra_font/kenvector_future_thin.ttf", 13, 0);*/
/*struct nk_font *clean = nk_font_atlas_add_from_file(atlas, "../../extra_font/ProggyClean.ttf", 12, 0);*/
/*struct nk_font *tiny = nk_font_atlas_add_from_file(atlas, "../../extra_font/ProggyTiny.ttf", 10, 0);*/
/*struct nk_font *cousine = nk_font_atlas_add_from_file(atlas, "../../extra_font/Cousine-Regular.ttf", 13, 0);*/struct nk_font_config cfg = nk_font_config(19);
cfg.merge_mode = nk_false;
cfg.oversample_h = 1;
cfg.oversample_v = 1;
cfg.range = nk_font_chinese_glyph_ranges();
cfg.coord_type = NK_COORD_UV;
struct nk_font *font = nk_font_atlas_add_from_file(atlas, "msyh.ttf", 19, &cfg);nk_d3d11_font_stash_end();
/*nk_style_load_all_cursors(ctx, atlas->cursors);*/
/*nk_style_set_font(ctx, &droid->handle)*/;
nk_style_set_font(ctx, &font->handle);
}
在线
晕哥这个厉害了
离线
柳暗花明又一村,终于找到解决方案了: https://github.com/skeeto/opengl-demo
如果您的GPU不支持OpenGL 3.3并且您使用Mesa 10.0+,则可以使用环境变量强制渲染软件 LIBGL_ALWAYS_SOFTWARE=1。
把环境变量强制加上,终于搞定这个棘手的问题:
yunge@ubuntu:/tmp/nuklear/example/bin$ LIBGL_ALWAYS_SOFTWARE=1 ./extended
piemenu selected: 4
pushed!
piemenu selected: 4
piemenu selected: 4
piemenu selected: 4有图有真相:
https://whycan.cn/files/members/3/QQ20180218185909.png
补充一下顺序,
安装(ubuntu 16环境):
sudo apt install libglew-dev
sudo apt install libglfw3-dev
(很遗憾,这两部没有碰到任何问题,开心脸.jpeg)
下载https://github.com/vurtun/nuklear.git
进入~/nuklear/example 目录
make
进入 ~/nuklear/example/bin$
~/nuklear/example/bin$ ./extended
demo画面应该就出来了
离线
晕哥,能把VS的工程放出了吗?这个看起来不错
离线
在线
晕哥 说:演技担当黄晓明 说:晕哥,能把VS的工程放出了吗?这个看起来不错
好像直接新建一个 Win32 窗口项目, 然后添加文件就可以了。
我回去看看,还在不在电脑,如果有就传上来.
下载地址: nuklear_debugdump.7z
由于git仓库太大,比 .git 目录删除了。
工程文件是哪个?
离线
晕哥 说:晕哥 说:好像直接新建一个 Win32 窗口项目, 然后添加文件就可以了。
我回去看看,还在不在电脑,如果有就传上来.
下载地址: nuklear_debugdump.7z
由于git仓库太大,比 .git 目录删除了。
工程文件是哪个?
nuklear_debugdump\demo\gdi\gdi.vcxproj
nuklear_debugdump\demo\d3d9\gdi.vcxproj
nuklear_debugdump\demo\d3d11\gdi.vcxproj
在线
演技担当黄晓明 说:晕哥 说:下载地址: nuklear_debugdump.7z
由于git仓库太大,比 .git 目录删除了。
工程文件是哪个?
nuklear_debugdump\demo\gdi\gdi.vcxproj
nuklear_debugdump\demo\d3d9\gdi.vcxproj
nuklear_debugdump\demo\d3d11\gdi.vcxproj
请问下这个能在stm32跑嘛?
或者说有没有推荐能在stm32上实现矢量字体的方法
离线
晕哥 说:演技担当黄晓明 说:工程文件是哪个?
nuklear_debugdump\demo\gdi\gdi.vcxproj
nuklear_debugdump\demo\d3d9\gdi.vcxproj
nuklear_debugdump\demo\d3d11\gdi.vcxproj请问下这个能在stm32跑嘛?
或者说有没有推荐能在stm32上实现矢量字体的方法
看起來應該可以在 STM32 跑
libfreetype: https://whycan.cn/t_741.html
离线
mark
离线
请问这个和littlevgl那个更适合在单片机上跑啊?带lcd control的单片机
离线
ddddddddddddddddddddddddddddd
离线
mark一下。。。。
离线
这个GUI真是碉堡了
离线
厉害了。。。高手太多了。
离线
感谢楼主这个帖子,全网只此一家!!!
离线
源码只有一个h文件,还是2.5万行的,这个够厉害。。。
离线
是比较厉害,GUI代码不少了,学习不完
离线
看了一下,底层都是调用windows的api啊,应该没法移植到单片机上吧
离线
理论上 是可以移植到mcu上的
有个问题,为什么我下载来的h文件,是5k行的。。。
离线
好东西,可以在VS上编译, 就比较好玩了。
离线
一个头文件,2.5万行,厉害了。。。
离线