Comments (13)
I did that intentionally, but you have a good point.
Your suggested solution does not handle font rendering and tesselation properly. If you look the second image carefully you'll see that the fonts are blurry and the tesselation especially on the small blue dots is quite coarse.
I wonder if the proper solution would pass in scale to nvgBeginFrame(), or whether we would expect the user to do the scaling manually. I'm slightly in favor of adding scale to nvgBeginFrame(), what do you think?
The implementation would be something like:
in example code:
int winWidth, winHeight;
glfwGetWindowSize(window, &winWidth, &winHeight);
nvgBeginFrame(vg, width, height, (float)width/(float)winWidth, (float)height/(float)winHeight);
in nvgBeginFrame:
void nvgBeginFrame(struct NVGcontext* ctx, int width, int height, float sx, float sy)
{
...
vg->nstates = 0; // probably should add state reset there anyways...
nvgSave(vg);
nvgReset(vg);
nvgScale(vg, sx, sy);
}
Maybe the retina scaling could be part of initialization too.
from nanovg.
As a user, I would definitely not want to do it manually, so adding sx, sy to nvgBeginFrame would work best for me.
from nanovg.
Do you know how other libraries do it? glfw seems to have window size vs. framebuffer size. That is one option. HTML5 has devicePixelRatio [1].
[1] http://www.quirksmode.org/blog/archives/2012/06/devicepixelrati.html
from nanovg.
SDL2 is the same as GLFW, just with different names: SDL_GetWindowSize and SDL_GL_GetDrawableSize
from nanovg.
With Anttweakbar you call TwWindowSize with the window size reported by glfwGetWindowSize, rather than framebuffer size, but then there is a fontscaling option. I forgot the logic of this, but it works seamlessly across retina and non-retina displays.
window_container.get_window_size(&w, &h);
window_container.get_framebuffer_size(&fb_w, &fb_h);
int scale = (fb_w <= w) ? 1 : fb_w / w;
if(scale > 1)
{
std::stringstream s;
s << " GLOBAL fontscaling=" << scale << " ";
TwDefine(s.str().c_str());
}
from nanovg.
CoreGraphics seems to use some sort of scale value:
http://stackoverflow.com/questions/5414631/retina-display-core-graphics-font-quality
I think one scale value is probably the best. A name like contentScale, pixelRatio or devicePixelRatio could work, it would at least be consistent what is being used out there. Probably makes sense to put that as parameter in nvgBeginFrame since we pass the frame buffer size there too (vs. passing it on init).
Whether we should pass frame buffer or window size to nvgBeginFrame is good question too. HTML canvas and CoreGraphics [1] both seem to use window coordinates in this kind of case too, maybe that is the correct option.
Going this route, I think the best way to implement pixel scaling is to store the device pixel ration in to the context and then scale ctx->tessTol and ctx->distTol with pixel ratio before use (or make a function which calculates them based in pixel ratio, call in init too), in addition multiply 'scale' in nvgText() by pixel ration too.
Note to self, nvgTextBounds and nvgVertMetrics need scaling too.
from nanovg.
Would you like to make a PR about these retina support or should I go ahead and implement it?
from nanovg.
PR (purchase request?). Please do go ahead :)
from nanovg.
PR = pull request, I'll implement that.
from nanovg.
Regarding PR, I swear I knew that.
Regarding adding scale support, I was just looking at your comments again and I just realized how simple it would be from your first response, I was previously under the impression that it would require further changes deeper in NanoVG (e.g. to how tessellation is handled). Sorry about that.
from nanovg.
no worries, it's almost done :)
from nanovg.
This is implemented now, can you try it out? One thing left to do is to up the cache size too based on retina display. The implementation did not end up being as simple as I hoped, while working on this I also found a couple of bugs in my demo code which were not showing up on non-retina displays :)
from nanovg.
It works. It looks absolutely stunning too.
from nanovg.
Related Issues (20)
- Layer based drawing HOT 3
- outlines donβt draw properly HOT 2
- Edges of the curve are drawn at an angle HOT 9
- Draw an Arc with a Hole HOT 2
- Multiple scissors HOT 3
- Draw fill problems for complex polygons HOT 2
- Fix for MinGW: Replace -lGLEW with -lglew32
- support android ARGB format HOT 1
- Memory leak with freetype fonts [fix] HOT 4
- nvgArc does some ugly overdraw HOT 2
- [nvgTextBounds] string ending with space does not return expected bounds HOT 2
- `nvgArc` and `nvgArcTo` parameters correspondence and conversion
- building into a shared library HOT 6
- Transformation from Screen Space to World Space? HOT 1
- Arab, Hebrew and Persian
- ANSI Color Escape Sequences HOT 2
- Richtext HOT 2
- Proposal: Support for different NVGcontext types
- Frequent JVM crashes HOT 2
- nvgCreateGL failed
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nanovg.