Adam's Lair Forum

game development and casual madness
It is currently 2018/12/14, 06:05

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: TextRenderer with icons
PostPosted: 2018/08/30, 16:53 
Novice Member
Novice Member

Joined: 2017/08/13, 16:10
Posts: 12
Role: Hobbyist
Hi,

I'm having trouble getting icons to work in TextRenderer. What values should I write for the uvRect? There are four input boxes for uvRect in the editor, are the top two boxes for x,y and the bottom two width and height? And are the coords relative to the center or topleft of my texture?

If I have a 128x16 IconMat-file, (8 icons, each 16x16 px large), and let's say I want to display the third icon (/i[2] in the SourceText), what are the correct values for the icon in the Icons-array? (Offset, Size and uvRect)

No matter what I try I just get semi-transparent grey boxes displayed instead of my actual icons. (SourceText is : "testing icon one: /i[0], testing icon 2: /i[1])


Top
 Profile  
 
PostPosted: 2018/08/30, 20:28 
Site Admin
Site Admin
User avatar

Joined: 2013/05/11, 22:30
Posts: 2063
Location: Germany
Role: Professional
Hey there,

here's a quick example where I use the Duality icon texture as a text icon:
Image
Image

As you can see, I added two icons, one where you can see the full logo, and one where you can see the center part of it.

The UV coordinates are relative coordinates on the texture you use, where [0, 0] is in the textures upper left, and [1, 1] is in the lower right. Each uvRect describes a rectangle within UV space - just like you said, the upper row is X and Y, and the lower row is width and height. The easiest way to use icons is to put them all in a power-of-two texture (where all edges are 2^N pixels big) and calculate the UVs you need.

In your case, your 128x16 IconMat file with 16x16 icons should have uvRect values with a width of 16px / 128px = 0.125 and a height of 16px / 16px = 1.0. Since you only have one row of icons, all Y values are 0.0, and your X values will be 0.0, 0.125, 0.25, 0.375, and so on.

The size value is how big the icon is when rendered, so if you want it to be 64x64 pixels big, that's your size. Make sure it matches the aspect ratio of your icon, or it will be stretched.

The offset is just a pixel offset for displaying the icon slightly next to its intended position, so you can just leave all of the offsets at zero.

_________________
Blog | GitHub | Twitter (@Adams_Lair)


Top
 Profile  
 
PostPosted: 2018/08/31, 11:12 
Novice Member
Novice Member

Joined: 2017/08/13, 16:10
Posts: 12
Role: Hobbyist
Fantastic explanation, thank you so much! I've made it work now.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: Google [Bot] and 19 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group