• Advertisement
Sign in to follow this  

GUI Scaling

This topic is 1668 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm wondering what the best way to scale GUI elements to different resolutions would be.

I'm using relative sizing and all that for the elements, but the problem is the fonts. I cannot just simply scale the fonts as it will make them look very blurry in all but the 'correct' resolution (or x2 etc.) unless maybe the fonts are very large.

 

The only thing I can think of at the moment would be to have multiple pre-configured gui sizes that you have set up and tweaked and choose the closest one to the current resolution, but then again you are going to end up with slightly different gui sizes between the presets and it will be somewhat inconsistent even still because of how fonts tend to look different at different point sizes.

 

Any ideas would be much appriciated!
Thanks

 

EDIT:
I guess another option is to just not worry about it and create a GUI for a common middle-ground resolution and let it get big/small depending on the user end resolution.

Edited by James Leighe

Share this post


Link to post
Share on other sites
Advertisement
You could just use the biggest font that is smaller than the ideal size for the asked gui.

So if i just realize a bit the font won't change and will just take less space, but if i reside more it will eventually switch to a larger size.

Share this post


Link to post
Share on other sites

My resolution-independent GUI uses a dynamic texture atlas of glyphs which is automatically populated with the most recently used characters as they are needed. I use Freetype to generate the glyph textures and they are placed in atlas textures corresponding to the desired font size, generally with a separate atlas for 8pt, 16pt, 32pt, etc fonts.

 

At runtime, the renderer picks the smallest previously cached glyph to use (or adds a new glyph to the atlas) that is not more than double the requested font size. You need a hash map cache from character ID to glyph entries, each of which contains a list of pointers to the atlas textures for the different sizes for the glyph. The renderer then builds a vertex buffer of quads/texture coordinates which it renders.

 

This way, you can build your GUI at some standard resolution, and then apply a scale factor to all sizes/positions when operating at different resolutions that produces a pixel-perfect result.

Share this post


Link to post
Share on other sites

i discovered that d3dxfonts are SLOW, so i replaced them with d3dxsprites, which scale quite nicely and are much faster.

 

one approach to resolution independant GUI components:

 

a virtual 10000x10000 screen coordinate system. all gui routines (sprites, text, etc) convert the virtual coords to current rez before drawing.

 

so you code:

txt(5000,5000,"Hello world");

and it draws "Hello world" in the middle of the screen, whether you're in 1024x768, 1200x900, or whatever.

 

this really is the slickest way to go. but usually a project has already been hardcoded to some rez, which means fixing a lot of rez dependent code.

Share this post


Link to post
Share on other sites

I generally use a FBO for this (OpenGL). Render the scene at a fixed resolution, then render the screen texture to a quad that stretch to the entire screen.

Might not work for old computer though.

Edited by Vortez

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement