This function draws a graph of a function in the memory:
GetShape()->draw_func =
[&](const Rect& r)
{
graph.NewFrame();
graph.SetFlagAdv(1, MGL_NO_SCALE_REL);
graph.SetScaleText(false);
graph.SetSize(r.width, r.height, false);
graph.SubPlot(1, 1, 0, "#");
graph.InPlot(0.05, 0.95, 0.05, 0.95);
graph.SetRanges(x_left, x_right, y_bottom, y_top);
graph.SetFontSize(level);
std::string f = "{" + format.color.ToRGB() + "}";
graph.Axis("xy", std::string(f + "-1").c_str(), "h-1");
if (format.grid_width > 0)
graph.Grid("xy", std::string("h" + std::to_string(format.grid_width) + f).c_str());
graph.SetQuality(MGL_DRAW_NORM);
for (const Plot& p : plots)
{
auto& x = p.x;
auto& y = p.y;
if (!x.empty() && !y.empty())
{
mglData x_data(x.size());
mglData y_data(y.size());
x_data.Set(x);
y_data.Set(y);
f = "{" + p.format.color.ToRGB() + "}-" + std::to_string(p.format.width);
graph.Plot(x_data, y_data, f.c_str());
}
}
const unsigned char* picture = graph.GetRGBA();
std::vector<unsigned char> arr(picture, picture + 4 * (graph.GetWidth() * graph.GetHeight()));
window->DrawImage(r.left + 1, r.top + 1, r.width, r.height, arr);
};
I get such a graph:
As you see the line is not very beautiful. How can I resolve it? I tried to set quality to MGL_DRAW_LMEM. The result is much better, but the grid is not shown. Is this issue about antialiasing? How can I turn it on or off? If width of graph >= 2, the line is solid, but I need to draw it in width = 1 also.