Thread Tools Display Modes
04-11-10, 09:49 AM   #1
TravisWatson
A Deviate Faerie Dragon
Join Date: Apr 2010
Posts: 11
Lightbulb Pixel Perfection for Specific Resolution

This post has been updated per Haleth's information below. Thanks Haleth!

I came across an issue I didn't like while designing my UI: in-game pixels were not "real" pixels. They were close, but not exactly. So sometimes textures/borders/etc would get fudged when WoW scales up from its in-game resolution to your monitor's resolution.

The solution is to manually set the uiscale CVar (which just stores the value from this slider in the Video Options).

Here's the quick'n'dirty macro line:

Code:
/run SetCVar("uiScale", 768/string.match(({GetScreenResolutions()})[GetCurrentResolution()], "%d+x(%d+)"))
Here's the explanation and longer more hands-on method:

To calculate the value, you need your resolution height (mine was 1050 for a 1680x1050 resolution) and need to know the game's height is always (?) 768. You can verify that your in-game height is 768 by running the following lines:

Code:
/console useuiscale 1
/console uiscale 1
/run print(GetScreenHeight())
Your UI scale is the ratio between your actual resolution and the in-game resolution. For me, it's:

Code:
768 / 1050 = 0.731428571
/console uiscale 0.731428571
NOTE: The minimum value is 0.64. Below 0.64 will not work!

You can see what your resulting size is by:

Code:
/run print(GetScreenWidth(), "x", GetScreenHeight())
And there you have it, the exact resolution of your monitor (within floating point accuracy) to work with when designing your UI. Since we were modifying a CVar, this will save across sessions.

Disclaimer: This is possibly/probably a bad idea if you plan to package your UI. I use it only for my own UI.

Last edited by TravisWatson : 04-11-10 at 11:11 AM.
  Reply With Quote
04-11-10, 10:04 AM   #2
Gsusnme
A Wyrmkin Dreamwalker
AddOn Author - Click to view addons
Join Date: Jun 2008
Posts: 55
I too have noticed "fudging" or "blending" with my UI but I always simply thought of it as a limitation of the UI overlay, thanks so much for this! Now my OCD is satiated.

Last edited by Gsusnme : 07-03-10 at 12:27 AM.
  Reply With Quote
04-11-10, 10:08 AM   #3
TravisWatson
A Deviate Faerie Dragon
Join Date: Apr 2010
Posts: 11
@Gsusnme, Glad I could help! Indeed it was also my OCD that led me down this path!
  Reply With Quote
04-11-10, 10:30 AM   #4
Haleth
This Space For Rent
 
Haleth's Avatar
Featured
Join Date: Sep 2008
Posts: 1,173
It's much easier if you just do:

/script SetCVar("uiScale", 768/string.match(({GetScreenResolutions()})[GetCurrentResolution()], "%d+x(%d+)"))
  Reply With Quote
04-11-10, 10:42 AM   #5
TravisWatson
A Deviate Faerie Dragon
Join Date: Apr 2010
Posts: 11
Originally Posted by Haleth View Post
It's much easier if you just do:

/script SetCVar("uiScale", 768/string.match(({GetScreenResolutions()})[GetCurrentResolution()], "%d+x(%d+)"))
Ha, I didn't even look at the height! Had no clue that it always sets that value to 768. Good call! Will this always be the case? Is 768 *always* the base height?
  Reply With Quote
04-11-10, 10:55 AM   #6
Haleth
This Space For Rent
 
Haleth's Avatar
Featured
Join Date: Sep 2008
Posts: 1,173
Originally Posted by TravisWatson View Post
Ha, I didn't even look at the height! Had no clue that it always sets that value to 768. Good call! Will this always be the case? Is 768 *always* the base height?
Yes, afaik the WoW screen height is always 768.
  Reply With Quote
04-11-10, 11:38 AM   #7
nightcracker
A Molten Giant
 
nightcracker's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 716
UI Scale is one way, but when I'm making an addon, I can't set the users UI scale to my value. So I have to make a workaround. If I scale any value with the following function, there comes out the value needed to represent the amount of "virtual pixels" needed by the frame to get the amount of "real pixels".

Code:
local mult = SetCVar("uiScale", 768/string.match(({GetScreenResolutions()})[GetCurrentResolution()], "%d+x(%d+)"))/GetCVar("uiScale")
local function scale(x) return mult*x end

someframe:SetHeight(scale(10))
someframe:SetWidth(scale(10))
I implemented this method in TukUI and ncUI to get them both pixelperfect.
__________________
Three things are certain,
Death, taxes and site not found,
You, victim of one.
  Reply With Quote
04-11-10, 01:28 PM   #8
Saiket
A Chromatic Dragonspawn
 
Saiket's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 154
If you don't want to override the user's uiScale, you can use the following code to position a frame on real pixel boundaries: http://pastey.net/134131

It includes some test code that renders pixel-wide nested borders. The top one in this screenshot is adjusted, the bottom one isn't.
  Reply With Quote
04-11-10, 06:12 PM   #9
TravisWatson
A Deviate Faerie Dragon
Join Date: Apr 2010
Posts: 11
Originally Posted by nightcracker View Post
UI Scale is one way, but when I'm making an addon, I can't set the users UI scale to my value.
I guess I should have been clear, I did not intend to create a standalone addon that modified the UI Scale. My whole purpose was to set my overall resolution for every addon to use, while maintaining my screen resolution so that everything looks pixel perfect and I can create my custom textures more easily. The way this should be used for addon creators is to create their addons/ui packs in a precise and realistic environment, which is in my opinion when the number of pixels you're working with is identical to your native resolution.

In fact, if I understand what you guys are doing here, I highly disapprove. It looks like you guys are making your addons ignore the UI scale... and in my opinion, this is a terrible idea! This is not what I had in mind AT ALL. Your addons should never ignore a user's UI scale. If I found one that did, I would probably promptly trash it.

Please correct me if I misunderstood what this code is doing.
  Reply With Quote
04-26-10, 02:48 PM   #10
Sideshow
A Flamescale Wyrmkin
 
Sideshow's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 103
Originally Posted by nightcracker View Post

Code:
local mult = GetCVar("uiScale", 768/string.match(({GetScreenResolutions()})[GetCurrentResolution()], "%d+x(%d+)"))/GetCVar("uiScale")
local function scale(x) return mult*x end

someframe:SetHeight(scale(10))
someframe:SetWidth(scale(10))
You say SetCVar / GetCVar ??? I corrected it to GetCVar / GetCVar
I'll probably lack knowledge, but all scale(1) does is multiply by 1.
So scale(23.124578) is still 23.124578 with this function of yours

Last edited by Sideshow : 04-26-10 at 02:51 PM.
  Reply With Quote
06-29-10, 11:32 PM   #11
zohar101
A Cyclonian
 
zohar101's Avatar
Join Date: Jan 2010
Posts: 43
Originally Posted by TravisWatson View Post
And there you have it, the exact resolution of your monitor (within floating point accuracy) to work with when designing your UI. Since we were modifying a CVar, this will save across sessions.
So...do you have to hit this macro once and that's it or every single time you log in? Cause that would get a little annoying after a while...
  Reply With Quote
06-30-10, 01:02 AM   #12
Aarokh
A Cyclonian
 
Aarokh's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 40
You only have to hit this macro once if you are not switching between window mode and fullscreen mode frequently.

Basically you have to hit it once everytime you change something in your graphic settings (Multisampling for example) and hit apply.
  Reply With Quote
06-30-10, 02:04 AM   #13
sakurakira
A Chromatic Dragonspawn
 
sakurakira's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 151
I have a problem... I read about this "pixel perfection" method a while ago on these forums, but it does not work exactly for all resolutions.

My resolution is 1440x900. When I put in 768/900, the result is 0.85333333333333333 to infinity. I edited my config file so that the scale is uiScale "0.85333333333333". But since it's not an exact number, the resultant UI scale is therefore not accurate, but is only the closest available.

If I use /run print(GetScreenWidth(), "x", GetScreenHeight()) to see the resolution my number gets me, the result is 1439.9999662615 x 899.9999969073.

I set all addons to use 100% scale. The result of all of this is that some of my addons have 1 px borders: my minimap, grid, tooltips, and those look fine. I also have graphic replacements with 1 px borders that sometimes appear smudged.

Any help/adivce?
__________________
Arise, my champion!

Last edited by sakurakira : 06-30-10 at 02:07 AM.
  Reply With Quote
06-30-10, 04:38 AM   #14
Wella
A Rage Talon Dragon Guard
 
Wella's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 322
I also have a resolution of 1440x900 and I used Google to work out 768/900 for me. The result was 0.85 follow by seven 3s:

0.853333333

Try this in your command prompt and everything should be fine.
__________________
Addons I use, not that any of you care
* Bejeweled - For boring 5 minute flights to Tanaris
* Genie - Blizzard really should have implemented bag sorting by now
* ncHoverBind - I'm a Lock, what can you expect?
* oGlow - Agan, a missing feature
* Recount - Derp
* ShooShards - Another missing feature


"Your idea is good. So i will try it."
- popmissa
  Reply With Quote
06-30-10, 05:01 AM   #15
Ailae
A Rage Talon Dragon Guard
 
Ailae's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2007
Posts: 318
It's still 0.853333.. repeating to infinity. Google just doesn't display it properly.
__________________
Oh, the simulated horror!
  Reply With Quote
06-30-10, 05:04 AM   #16
Wella
A Rage Talon Dragon Guard
 
Wella's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 322
I know what it is, but I used what Google displayed and got a perfect result. The maths here aren't important, he was just asking for a way to solve the problem.

PS: The correct term is 'recurring'. :P
__________________
Addons I use, not that any of you care
* Bejeweled - For boring 5 minute flights to Tanaris
* Genie - Blizzard really should have implemented bag sorting by now
* ncHoverBind - I'm a Lock, what can you expect?
* oGlow - Agan, a missing feature
* Recount - Derp
* ShooShards - Another missing feature


"Your idea is good. So i will try it."
- popmissa

Last edited by Wella : 06-30-10 at 05:06 AM.
  Reply With Quote
06-30-10, 05:11 AM   #17
Ailae
A Rage Talon Dragon Guard
 
Ailae's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2007
Posts: 318
Let's hope those seven 3's are magical enough then.

Actually, it's either recurring or repeating - http://en.wikipedia.org/wiki/Repeating_decimal
__________________
Oh, the simulated horror!
  Reply With Quote
10-09-10, 05:44 PM   #18
Carighan
Guest
Posts: n/a
Game's height was 819,2 for me. :O

Anyways, worked amazingly awesome. Big thanks.
  Reply With Quote
10-13-10, 05:31 PM   #19
Gnarfoz
A Deviate Faerie Dragon
 
Gnarfoz's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2006
Posts: 18
4.0.1 makes this unnecessary, it seems?

Turning UIScale off seems to give the desired effect now.

(GetScreenHeight returns 1050 for me, which is my actual Y-resolution.)
__________________
Be nice to nerds, chances are you might end up working for one. -- Charles J. Sykes
  Reply With Quote
10-13-10, 09:49 PM   #20
Barjack
A Black Drake
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 89
Originally Posted by Gnarfoz View Post
4.0.1 makes this unnecessary, it seems?

Turning UIScale off seems to give the desired effect now.

(GetScreenHeight returns 1050 for me, which is my actual Y-resolution.)
The general technique is still useful if you want to be able to scale frames without scaling certain elements (e.g. 1-pixel border on a scalable map). Or for people who use uiscale but want a certain element to render at pixel scale. That said I'm still not entirely sure what needs to be changed in order for that to work in 4.0.1.
  Reply With Quote

WoWInterface » Developer Discussions » Tutorials & Other Helpful Info. » Pixel Perfection for Specific Resolution

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off