Skip to content

Commit

Permalink
RenderNvgToFrameBuffer: improve antialias
Browse files Browse the repository at this point in the history
  • Loading branch information
pthom committed Jan 11, 2024
1 parent 45ff68a commit 72e5359
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#include "nanovg_demo/nanovg_demo.h"

// On peut modifier CustomBackground durant l'execution


struct MyNvgDemo
{
Expand Down Expand Up @@ -64,9 +66,8 @@ int main(int, char**)
{
auto vg = ImmApp::NanoVGContext();
appState.myNvgDemo = std::make_unique<MyNvgDemo>(vg);
float scale = ImGui::GetIO().DisplayFramebufferScale.x;
int nvgImageFlags = 0; //NVG_IMAGE_FLIPY | NVG_IMAGE_PREMULTIPLIED;
appState.myFramebuffer = NvgImgui::CreateNvgFramebuffer(vg, (int)(1000 * scale), (int)(600 * scale), nvgImageFlags);
appState.myFramebuffer = NvgImgui::CreateNvgFramebuffer(vg, 1000, 600, nvgImageFlags);
};
runnerParams.callbacks.BeforeExit = [&]()
{
Expand Down
10 changes: 9 additions & 1 deletion external/nanovg/nvg_imgui/nvg_imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,15 @@ namespace NvgImgui
if (clearColor.w > 0.f)
FillClearColor(clearColor);

float pixelRatio = ImGui::GetIO().DisplayFramebufferScale.x;
// Note:
// - internally, we use NVGLUframebuffer, provided by NanoVG
// - NVGLUframebuffer does not handle pixelRatio
// => using pixelRatio=DisplayFramebufferScale would lead to non anti-aliased rendering
// => you may want to create texture of bigger size and scale down the drawing, in order to
// improve the quality of the rendering

// float pixelRatio = ImGui::GetIO().DisplayFramebufferScale.x;
float pixelRatio = 1.f;
nvgBeginFrame(vg, texture->Width, texture->Height, pixelRatio);

// Flip the y-axis
Expand Down

0 comments on commit 72e5359

Please sign in to comment.