Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
This question was closed Feb 27, 2016 at 02:38 PM by ado112 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by ado112 · Feb 24, 2016 at 10:22 PM · uvsfontscalculations

How do I calculate custom font character texture uvs from .fnt file

So i made a little .fnt file using shoebox and it was nothing else but a text file that contained some stuff about character positions/sizes on the image (in my case format of image is 186x189), and the main part of that .fnt file looks like this:

 char id=65 x=93 y=26 width=16 height=25 xoffset=0 yoffset=55 xadvance=17 page=0 chnl=0 letter="A"

so the most important info that I get from that are x,y,width and height. Like this: alt text

And in the custom font index is the id and the there are 2 rects, one is Vert where I just add W = width and H = -height and after that one there is the Uv rect and I need a few formulas how to calculate those uvs from those x,y,width and height values from fnt file. As far as I know values there are in range from 0 to 1 so to calculate x and w I just divided x and width by image width and that worked, but when I tried the same with y and h and divided them by image height I haven't got the correct uv values and instead of getting letter A i got... (part of the image that is... not 'a'), so what is the right formula to calculate those y and h values?

fnt.png (6.0 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by ado112 · Feb 27, 2016 at 02:37 PM

After a few hours of "thinking", I ended up with this:

 UV.x = x / imageWidth;
 UV.y = (imageHeight - (y+height)) / imageHeight;
 UV.w = width / imageWidth;
 UV.h = height / imageHeight;
 
 Vert.x = 0;
 Vert.y = -yoffset;
 Vert.w = width;
 Vert.h = -height;


Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Follow this Question

Answers Answers and Comments

45 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How can I change the UV's on a font and then save it so that these changes are permanent? 0 Answers

How to Make Proper Font used in WebGL build? 2 Answers

Summing floats went terribly wrong 0 Answers

Scrolling AND frame animating texture at the same time? 1 Answer

Text Mesh Pro no outline settings on costume font 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges