I followed the documentation on how to add my own custom font into NanoGUI, but the code seems outdated.
The documentation says:
int fancyFont = nanogui::createFontMem(screen->nvgContext(), "fancy", "fancy.ttf");
// -1 signals error loading the font
if (fancyFont == -1)
throw std::runtime_error("Could not load 'fancy.ttf'!");
new nanogui::Label(window, "Label Text", "fancy");
However this requires a resources.h file - which doesn't exist. This means createFontMem and nvgContext are both invalid here, and my font will not work. I tried replacing fonts, and adding it to themes.cpp but found it also broke the build process because it "wasn't defined in this scope".
I am editing the example4.cpp file as I love the OpenGL cube and want to incorporate it, however I cannot seem to inject my own font into the code. I posted the part where I need to inject it:
class ExampleApplication : public nanogui::Screen {
public:
ExampleApplication() : nanogui::Screen(Eigen::Vector2i(750, 750), "APIHub", false) {
using namespace nanogui;
Window *window = new Window(this, "");
window->setPosition(Vector2i(0, 0));
window->setLayout(new GroupLayout());
//Label with custom font here//
mCanvas = new MyGLCanvas(window);
mCanvas->setBackgroundColor({100, 100, 100, 255});
mCanvas->setSize({250, 250});
Widget *tools = new Widget(window);
tools->setLayout(new BoxLayout(Orientation::Horizontal,
Alignment::Middle, 0, 5));
Button *b0 = new Button(tools, "Randomise Color");
b0->setCallback([this]() { mCanvas->setBackgroundColor(Vector4i(rand() % 256, rand() % 256, rand() % 256, 255)); });
Button *b1 = new Button(tools, "Randomise Rotation");
b1->setCallback([this]() { mCanvas->setRotation(nanogui::Vector3f((rand() % 100) / 100.0f, (rand() % 100) / 100.0f, (rand() % 100) / 100.0f)); });
performLayout();
}
Another problem also arose: the nanogui::Screen isn't attached to a variable here (or as I can find anyway), therefore I cannot seem to find any way to get an nvgContext out of it.
I followed the documentation on how to add my own custom font into NanoGUI, but the code seems outdated.
The documentation says:
However this requires a resources.h file - which doesn't exist. This means createFontMem and nvgContext are both invalid here, and my font will not work. I tried replacing fonts, and adding it to themes.cpp but found it also broke the build process because it "wasn't defined in this scope".
I am editing the example4.cpp file as I love the OpenGL cube and want to incorporate it, however I cannot seem to inject my own font into the code. I posted the part where I need to inject it:
Another problem also arose: the nanogui::Screen isn't attached to a variable here (or as I can find anyway), therefore I cannot seem to find any way to get an nvgContext out of it.
Please help!