Sign in to follow this  
WinRad

Font and Resolution problem(kind of :))

Recommended Posts

WinRad    122
Hiya guys :), Recently I just realized that when I create fonts and position them they "move" if the resolution is changed and that simply happens because font positioning is pixel based and not like 3D objects moving in space... So the problem is that the font 'changes' positions instead of proportionally shrinking/expanding like 3D objects do. If you know how to make the font remain proportionaly the same then please tell me. Thanks.

Share this post


Link to post
Share on other sites
legalize    116
Quote:
Original post by WinRad
If you know how to make the font remain proportionaly the same then please tell me.


When you change screen resolutions, determine the amount by which the point size of the font should increase and create a new ID3DXFont at the new size for your text. You'll also have to proportionately change the positions at which you're drawing text for the illusion to be complete.

Share this post


Link to post
Share on other sites
WinRad    122
Well that's just anoyying... this is yet anotehr thing Microsoft should have added support for(assuming its as easy as it sounds). Well anyway I'm a little confused by what you mean, so for some time I'll go online and see if I can find anything.

Now that I think about it there is another function related to text called D3DXCreateText(...), what about that? Does it proportionally position itself? I'm asking because I don't yet have any experience with it.

Thanks.

Share this post


Link to post
Share on other sites
Moe    1256
I've got a nice little class to handle this exact thing. I'll try and remember to post it tomorrow. (It's on my machine at home, and I don't have internet at home, so I'll have to bring it on a flash drive to work).

It's actually quite a simple problem to solve.

Share this post


Link to post
Share on other sites
Headkaze    607
Say the font size you use for 800x600 resolution is 32, then just calculate the new size based on that.

NewFontSize = (int) (32F / 800F * (float) newWidth);

So when your Window recieves a WM_EXITSIZEMOVE event or you detect a resolution change in fullscreen, then calculate the new font size like above and recreate your font.

Share this post


Link to post
Share on other sites
Moe    1256
Ah, I think I may have mistaken the original question. The class I wrote handles positions, not so much sizes. Either way, Headkaze is on the right track.

Share this post


Link to post
Share on other sites
WinRad    122
Ah no worries ;)

HeadKaze: Thanks for the reply! Though I thought it was much harder then that... me = suprised + 1 = very suprised. There is something that confuses me in your equation though; does the number 800 refer to the current width? Also is that equation for the height or width parameter of the D3DXCreateFont function? Finally but font size your ferring to the height parameter right?

Thanks again guys.

[Edited by - WinRad on August 14, 2008 7:57:16 PM]

Share this post


Link to post
Share on other sites
Headkaze    607
Quote:
Original post by WinRad
Ah no worries ;)

HeadKaze: Thanks for the reply! Though I thought it was much harder then that... me = suprised + 1 = very suprised. There is something that confuses me in your equation though; does the number 800 refer to the current width? Also is that equation for the height or width parameter of the D3DXCreateFont function? Finally but font size your ferring to the height parameter right?

Thanks again guys.


The 800 is just the width in 800x600. The important part is the division to get the ratio. So you should decide, this font looks best at size 32 when the resolution is 800x600. Then when you change the resolution to 1024x768 it will calculate like so

newFontWidth = (int) (32F / 800F * 1024F);

So the new font size is "40". It makes sense to use the width because we read text horizontally. So if the display is widescreen you will be calculating a larger font size.

I didn't realise you specified width and height for D3DXCreateFont() I dont use that because I have my own font renderer. But the above equation can be used for both width and height as well.

newFontWidth = oldFontWidth / oldScreenWidth * newScreenWidth
newFontHeight = oldFontHeight / oldScreenHeight * newScreenHeight

But I can see problems with the font stretching in strange ways if you go to a different screen ratio (eg. 4:3 to 16:9). So I tend to just calculate based on the screen width and keep the font in proportion to that.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this