02 Quick Start - inanevin/LinaVG GitHub Wiki

Below is a bare-minimum implementation steps for drawing with LinaVG. As said in the home page, it's assumed that your application already has a graphics rendering backend setup and running, of course along with a window with a valid context. Check Custom Backends for more information.


// Include LinaVG
#include "LinaVG.hpp"

LinaVG::Drawer lvgDrawer;

// Bind rendering functions to your backend
lvgDrawer.GetCallbacks().drawDefault = std::bind(&GLBackend::DrawDefault, m_renderingBackend, std::placeholders::_1);
lvgDrawer.GetCallbacks().drawGradient = std::bind(&GLBackend::DrawGradient, m_renderingBackend, std::placeholders::_1);
lvgDrawer.GetCallbacks().drawTextured = std::bind(&GLBackend::DrawTextured, m_renderingBackend, std::placeholders::_1);
lvgDrawer.GetCallbacks().drawSimpleText = std::bind(&GLBackend::DrawSimpleText, m_renderingBackend, std::placeholders::_1);
lvgDrawer.GetCallbacks().drawSDFText = std::bind(&GLBackend::DrawSDFText, m_renderingBackend, std::placeholders::_1);

// Your application loop
while (m_applicationRunning)
{
    // Setup style, give a gradient color from red to blue.
    StyleOptions style;
    style.isFilled    = true;
    style.color.start = Vec4(1, 0, 0, 1);
    style.color.end   = Vec4(0, 0, 1, 1);

    // Draw a 200x200 rectangle starting from 300, 300.
    const Vec2 min = Vec2(300, 300);
    const Vec2 max = Vec2(500, 500);
    lvgDrawer.DrawRect(min, max, style);

    // Flush buffers, this will call your callback functions.
    lvgDrawer.FlushBuffers();

    // Shrink buffers.
    lvgDrawer.ResetFrame();
}

And that's basically it! Now you should have this on your screen, easy peasy.

1

There are a lot more to LinaVG in regards to usage, configuration, other shapes/lines/texts and styling, as well as basic threading support. Check out the rest of the Wiki or the example application to learn about them all.