# Supporting different resolutions

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

## Recommended Posts

Hi there! Until now I had no problem with this because my screen had always a resolution of 1024. So I created all my games with 1024x768 only... Like this:
// Setup new viewport
glViewport(0,0,(GLsizei)(1024),(GLsizei)(768));
glMatrixMode(GL_PROJECTION);

// Setup new perspective
gluPerspective(45.0f, (GLfloat)(1024)/(GLfloat)(768), 0.1f, 200.0f);
glMatrixMode(GL_MODELVIEW);


Then rendering objects worked without any problem. Also drawing a hud was relativly easy: Just switch to ortho mode, and draw quads on the screen from (0,0) to (1024,768). Now I want to support more than only one format. These sound good ;-) 320 x 240 - Handheld 640 x 480 - VGA 800 x 600 - SVGA 1024 x 600 - WSVGA 1024 x 768 - XGA 1280 x 720 - HDTV 1280 x 768 - WXGA 1280 x 800 - WXGA 1280 x 854 - WXGA 1280 x 1024 - SXGA 1400 x 1050 - SXGA+ 1440 x 900 - WXGA 1600 x 1200 - UXGA 1680 x 1050 - WSXGA+ 1920 x 1080 - HDTV 1920 x 1200 - WUXGA 2048 x 1536 - QXGA What I'd like to know is: What do I have to change in my initialisation code? Simply use the other resolution istead of 1024x768? Handle viewport and perspective seperately? How would my rendering code have to be changed? Or not at all? What about the HUD (ortho mode)? Can I still use my "0,0 - 1024,768" coordinate system somehow? Or do I have to rewrite the whole code for EVERY resolution? What happens with widescreen resolutions? How can HUD elements be centered? Or do I have to stretch them??? Questions over questions ;-) I hope you can bring some light into my drakness? Thanks a lot!!!! :-D

##### Share on other sites
The easiest way would be to ask the user for the desired resolution, store the result in a pair of variables, and refer to the variables throughout your code from there on whenever you need the resolution.

EDIT:
Actually, I'm not sure about the coordinate system part, since I've yet to fiddle with OpenGL's ortho. I'd say it probably is based on resolution, but someone more familiar will be able to better clear this up for you.

##### Share on other sites
Since all OpenGL maths are based on the viewport running from -1 to +1, changing the resolution will have no effect on your perspective matrix. The only things you need to worry about are calls to glViewport and maybe other things like glScissor (if you use them).

All the games I write have a 1024x768 'virtual' resolution. However you have to keep in mind that text made for 1024x768 probably won't come out right at 320x240 :)

##### Share on other sites
Your HUD might be a particular issue. You can scale an image a great deal and it still serves it's purpose, but an interface doesn't work that way. Just as an example set your screen resolution to 640x480 and try using your IDE. Chances are you'll have to make a lot of adjustments to the position and size of windows as well as fonts to make it usable.

If you're using polygons and textures to draw the hud then you can continue doing that the same as you are now and it will scale to the size the window actually is. If you use bitmaps only the raster position will scale. The bitmaps will still be the same pixel dimensions. So what was in the top right corner of the screen may only have a small part still on the screen at a lower resolution.

##### Share on other sites
yes it can be done.

Remember GL_VIEWPORT sets the render target and GL_ORTHO just sets the Projection matrix so you can keep your GL_ORTHO and GL_PERSPECTIVE calls the way they are.

How ever the FONT wont resize with it so you could either render font as textured quads or re-create font on resize.

##### Share on other sites
A minor issue to mention. Yes, just changing the viewport will make sure it all scales and looks the same, but lines that were neatly lines up before might now result in a position between two pixels, turning a crisp line at resolution X into a not so crisp line at resolution Y. But if that's really worth going over all your elements to adjust their position is questionable.

##### Share on other sites
I think the easiest way would be to change the way you have set up your ortho view. The perpective you may not even need to change. The ortho, I recommend yo go away from thinking in terms of pixels, rather units, like in 3d. If you setup the ortho with top bottom, left right, you can set it up from -10 to 10 for both axis and it will no longer matter what your resolution is. At z=0, the top will be 10, bottom -10. Just like in 3d. You will have to change a little the way you render the hud, since you were using the actual pixels to do it, but once you do a whole change in that form, you will never have to change again, even if the resolution changes. Another thing to consider is magnification and minification of your textures. Using the above method, you will get the same oncsreen size no matter what resolution you use, but if you go too little, you will get blocky textures, if you use LINEAR filtering though, it isn't too bad.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 14
• 11
• 29
• 15
• 41
• ### Forum Statistics

• Total Topics
634838
• Total Posts
3019568
×