Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

High DPI drawing #100

Closed
getzen opened this issue Jun 14, 2022 · 9 comments
Closed

High DPI drawing #100

getzen opened this issue Jun 14, 2022 · 9 comments
Labels
enhancement New feature or request stale Abandoned issue by inactivity

Comments

@getzen
Copy link

getzen commented Jun 14, 2022

It seems that Notan provides a high dpi window. For example ,on my iMac there are 2x as many physical pixels as logical pixels, which is great. However, the drawing shapes and text appears to be in normal/logical pixels, making them look low-res, so to speak. Placing shapes/text with logical coordinates is fine, but the appearance doesn't seem to be high dpi. Is this correct and intended? Is there a way to "turn on" high dpi drawing?

One workaround, as least for text, seems to be drawing at twice the needed font size and applying a scale of 0.5. That's very awkward though, and messes up the positioning.

I know dpi matters can get complicated, but I'm trying to understand Notan's approach.

@Nazariglez
Copy link
Owner

This is one of those things that I did not think about just yet.

Notan will adapt the viewport to avoid the hassle of different DPIs, but I have done nothing with the drawing API. Probably I could try to add a HighDPI mode to the draw API which adapts the shapes and text to the device DPI, not sure how it will interact with the transformation system, so I need to do some tests.

However, I am open to suggestions, what do you think will be a good approach?

@Nazariglez
Copy link
Owner

Nazariglez commented Jun 15, 2022

There is another option, disable the HighDPI https://github.com/Nazariglez/notan/blob/develop/crates/notan_winit/src/window.rs#L95. Not sure how it will look, right now it doesn't work because winit is not applying correctly this (I checked the code there diagonally). I will fix and send a PR but I am not sure if this is what you're looking for.

Related:

@getzen
Copy link
Author

getzen commented Jun 16, 2022

I'm no expert in these matters, but one approach is for high dpi drawing to be used automatically when in a high dpi environment. That way, it's transparent to the user. I believe this is how Macroquad handles it.

Of course, when it comes to texture clarity, the user will still need to provide 2x-sized textures and scale them down.

@Nazariglez
Copy link
Owner

I think that I'm going to do this in three steps:

Let's keep this issue open for now.

@Nazariglez Nazariglez added the enhancement New feature or request label Jun 16, 2022
@getzen
Copy link
Author

getzen commented Jun 16, 2022

Thank you for working on it!

@Nazariglez
Copy link
Owner

Pinning this blocker here to be able to check it without find in the winit repository: rust-windowing/winit#2322

@Nazariglez
Copy link
Owner

Half of this is already done: #122
I still need to think of a good way to draw easily:

  • Using primitives (viewport can adapt, this is already working)
  • Draw2d high dpi shapes (transformation matrix should work as usual).
  • Draw2d high dpi images (transformation matrix should work as usual).

I am thinking about adding a .resolution(n: f32) when creating an image, to indicate its resolution, and if the image is created the default image load I can use the suffix on the image's name (@2x.png) to set the resolution automatically.

Though this should have a way to disable it in case the user wants to manage High DPI in their own way, I may add to the Draw object a way to set resolution, maybe also to the Renderer object.

All of this is me just thinking loud.

@github-actions
Copy link

This issue is stale because it has been open for 60 days with no activity.

@github-actions github-actions bot added the stale Abandoned issue by inactivity label Nov 27, 2022
@github-actions
Copy link

This issue was closed because it has been inactive for 14 days since being marked as stale. Do not hesitate to open a new issue if you need it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request stale Abandoned issue by inactivity
Projects
None yet
Development

No branches or pull requests

2 participants