Adam's Lair Forum
https://forum.adamslair.net:80/

TextRenderer with icons
https://forum.adamslair.net:80/viewtopic.php?f=4&t=1245
Page 1 of 1

Author:  tufduck [ 2018/08/30, 16:53 ]
Post subject:  TextRenderer with icons

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])

Author:  Adam [ 2018/08/30, 20:28 ]
Post subject:  Re: TextRenderer with icons

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.

Author:  tufduck [ 2018/08/31, 11:12 ]
Post subject:  Re: TextRenderer with icons

Fantastic explanation, thank you so much! I've made it work now.

Page 1 of 1 All times are UTC + 1 hour [ DST ]
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/