Skip to content

Embedding guide

zxvnme edited this page Jul 12, 2019 · 1 revision

Guide how to embed zgui.

All you need to do is to "wrap" zgui rendering functions. Create proxy functions somewhere in your code.

void line(int x, int y, int x2, int y2, zgui::color c) noexcept
{
 /* draw line using your renderer */ 
}

void rect(int x, int y, int x2, int y2, zgui::color c) noexcept
{
 /* draw outlined rectangle using your renderer */ 
}

void filled_rect(int x, int y, int x2, int y2, zgui::color c) noexcept
{
 /* draw filled rectangle using your renderer */ 
}

void text(int x, int y, zgui::color color, int font, bool center, const char* text) noexcept
{
 /* draw text using your renderer */ 
}

void get_text_size(unsigned long font, const char* text, int& width, int& height) noexcept
{
 /* calculate text size here */ 
}

float get_frametime() noexcept
{
 /* return frametime */ 
}

After this, you have to overwrite zgui rendering functions with yours.

zgui::functions.draw_line = line;
zgui::functions.draw_rect = rect;
zgui::functions.draw_filled_rect = filled_rect;
zgui::functions.draw_text = text;
zgui::functions.get_text_size = get_text_size;
zgui::functions.get_frametime = get_frametime;
Clone this wiki locally