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

Can we have pixel-based sizing for fonts? #268

Closed
makoConstruct opened this issue Jan 29, 2018 · 8 comments
Closed

Can we have pixel-based sizing for fonts? #268

makoConstruct opened this issue Jan 29, 2018 · 8 comments

Comments

@makoConstruct
Copy link
Contributor

I'm trying to make a pixelated game, using pixel art and a pixel font. Regarding text, this doesn't seem to be doable? Point sizes are unusable for various reasons:

  • Why would a gamedev want to deal in Pts? What are Pts? Do they even have a fixed meaning?

  • My screen lies horribly about its DPI, many screens are the same. Very few screens give a completely accurate number. It can't really be relied on for anything.

  • If I had access to the measured DPI I might use it to scale the text down to compensate away the DPI-sensitive code further up the toolchain, but there doesn't seem to be a way to get that number.

To hammer my point home, I will supply a picture of the hello world example as it appears on my machine https://imgur.com/a/TUXLr

@icefoxen
Copy link
Contributor

A point is 1/72 of an inch.

I would love to have pixel-absolute sizes for fonts but I've yet to see a TTF renderer that really offers that. :-/ If we can figure out how to do it, we should do it.

For now the easiest way to get pixel-absolute fonts is to use bitmap fonts.

@uggwar
Copy link

uggwar commented Jan 29, 2018

The DPI is calculated from the display size, and not the size of the window. So running my little game in the same sized window on my internal and external monitor gave different font sizes. I forced ggez to use 72 as DPI and the problem was "solved". Not pretty, but not sure how to fix this properly.

@icefoxen
Copy link
Contributor

icefoxen commented Feb 5, 2018

Notes on how SDL2 does it:

14:07 < m12y_> Icefoz: i've relied on SDL2's drawable_size for text rendering and it's 
     worked perfectly for me (especially on mac/ios retina)
14:19 < m12y_> it returns the resolution in physical pixels (e.g. what you want to pass 
     to glViewport), whereas the normal `size` method returns the resolution in (DPI 
     aware) virtual pixels. i use`size` to lay out my UIs, and then `drawable_size` to 
     determine the actual font size to draw in that UI

@icefoxen
Copy link
Contributor

icefoxen commented Mar 9, 2018

Honestly just having a function that builds a Text to a given pixel size would be very easy, even if it gets abused. :|

@Sushisource
Copy link

I'm doing this by basically determining the pt -> pixel sizes experimentally and just saving that info statically for now. Having that function would be killer.

icefoxen added a commit that referenced this issue May 4, 2018
Should resolve #268 eventually, but currently needs testing and refactoring.
@icefoxen
Copy link
Contributor

icefoxen commented May 4, 2018

See commit 99fce38, it's a very small change. Just needs testing. Refactoring things a bit more nicely would be good, but this is all going to change when #362 lands (hopefully soon!), so this shouldn't be a huge deal.

@icefoxen
Copy link
Contributor

icefoxen commented May 4, 2018

Tested, it works.

@icefoxen
Copy link
Contributor

Closing. 😢 See #587 for basically the reason why.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants