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

Camera/Screen transformation support #87

Closed
wants to merge 2 commits into from

Conversation

PPakalns
Copy link
Contributor

@PPakalns PPakalns commented Mar 12, 2024

Added some support for rendering text with custom 2D world transformations
#4

Moved transformation matrix buffer to text_renderer to allow rendering multiple transformations of text and to be able to reuse the same texture atlas for all operations.

@PPakalns PPakalns changed the title Transformation support Camera/Screen transformation support Mar 12, 2024
@PPakalns
Copy link
Contributor Author

This is useful when world coordinate axis are flipped or when text clipping is not needed due to text being attached to the world.

@grovesNL
Copy link
Owner

Thank you! There's some unresolved conversation about this in #64 though. I think we need to figure out a strategy (e..g, separate vector pipeline) that allows for crisp text for non-axis aligned transformations. e.g., transforming 45 degrees won't look great right now. The vector approach from iced might be a good way to do it though

@PPakalns
Copy link
Contributor Author

PPakalns commented Mar 12, 2024

Thank you! There's some unresolved conversation about this in #64 though. I think we need to figure out a strategy (e..g, separate vector pipeline) that allows for crisp text for non-axis aligned transformations. e.g., transforming 45 degrees won't look great right now. The vector approach from iced might be a good way to do it though

Thank you for your feedback.

I would still suggest adding custom screen transformation matrix to the main pipeline too.

This makes more simple to use this library in cases like:

  • text is rendered on screen where coordinate axis are in different direction/order. For example current shader
    vert_output.position.y *= -1.0;
    already assumes that y axis must be pointing downwards and it causes problems if it is not the case in main application.
  • text is rendered on the screen in virtual coordinate system which can be moved around, zoomed in, zoomed out etc. In this case cropping can not be done based on screen resolution (box).

Of course coordinate transformations could be done before calculating ScreenResolution, buffer text size, text position, but it is more complex.

But still, it would be nice if Screen parameters (resolution/transformation buffer) could be moved to texture renderer so that:

  • Multiple viewports can be rendered by reusing the same texture atlas / caches, but having different screen resolutions / viewports.

Thank you for maintaining this library.

@grovesNL
Copy link
Owner

Of course coordinate transformations could be done before calculating ScreenResolution, buffer text size, text position, but it is more complex.

Yeah it's definitely possible we might want to expose this in some way, although it's better to do this before if possible. The crates glyphon uses internally will make use of the exact float position on screen (e.g., subpixel position for glyphs) to render small variations in the glyphs/layout. If you apply the transformation after all of that then the result will generally look much worse, but still maybe ok depending on the use case.

I'd definitely like to add some kind of vertical rendering (i.e., rotating exactly 90 degrees counterclockwise) to the existing renderer, but arbitrary transformations would benefit from some kind of separate vector renderer.

@PPakalns
Copy link
Contributor Author

Closing as #88 (support for reusing atlas for multi viewport rendering) was merged.

Some transformations can be applied by transforming all coordinates before passing them into glyphon.

@PPakalns PPakalns closed this Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants