为什么用
NanoGUI是一个支持OpenGL绘制的gui 库,也提供python的绑定(由pybind11实现)
优点
- 支持Mac、Windows和Linux,能够在windows平台上提供OpenGL3.x支持。
- 体积小
- 支持高清屏
- 使用lambda回调函数,逻辑清晰
缺点
- 维护不及时
- 功能少
- 缺少移动版本
总体来说,对于一般应用已经足够。
编译
从github下载:
git clone --recursive https://github.com/wjakob/nanogui.git
Mac/Linux上使用CMake构建,在Windows上生成VC solution后编译。注意windows上仅支持win64 build。vsiual studio 2015需要升级update 2 或update3(见NanoGUI::issures 201)。
C++实例
使用nanogui界面时刻直接从nanogui::screen 继承:
class App : public nanogui::Screen {
public:
App() : nanogui::Screen(Eigen::Vector2i(1024, 768), "NanoGUI Test") {
//初始化界面中第一个或多个菜单窗口
}
virtual void draw(NVGcontext *ctx) {
//更新界面
//...
Screen::draw(ctx);
}
virtual void drawContents() {
//使用OpenGL绘制窗口内容
}
virtual void Screen::drawAll() {
glClearColor(mBackground[0], mBackground[1