# Making a game “resize-safe”

It's one thing to get the graphics aligned perfectly, it's another to do this for every single resolution and not take too much time and/or make the code unreadable due to size. Games like Battlefield 3 and Minecraft seem to manage this. But what do they do to keep things from stretching or going off the screen? I don't know any algorithms to do this. I'd like some help on this topic. I've always programmed games that only handle a single resolution, so help would be appreciate.

The standard 3D pipeline is completely agnostic to screen resolution. For most projection matrix algorithms, including the "standard" ones in GL/D3D, an aspect ratio is part of the matrix allowing the projection to properly cope with different "shapes" of resolution. Just be sure to pass in the current resolution to the viewport setting routines calls and the current aspect ratio to the projection matrix routines and 3D is more or less automatically resolution-independent. The 3D projection/math all works in a normalized coordinate system where the upper-left corner of your screen is (-1,-1) and the bottom-right is (+1,+1). This is then mapped to the viewport which is defined by the resolution of the area you're drawing to (typically the whole client window), which is basically just the hardware mapping those NDC ranges to pixel coordinates. So long as the viewport's aspect ratio matches the one in the projection matrix the image won't be stretched; otherwise the projection matrix might be mapping 3D coordinates to a differently-shaped rectangle than what's actually being draw to.
For the 2D elements, these are specified independently of the screen. E.g. a compass in the upper right is located with its upper-right corner at (0.95, 0.05) or some such, and its size can be specified to be a ratio of the vertical or horizontal resolution as most appropriate. The GUI might be specified in pixels which is mapped back to those ratios for GPU rendering (which then maps them back to pixels for final rasterization). Point is, just don't use fixed offsets for 2D elements, rather use relative coordinates and sizes to the corners/sides of the viewport and then the 2D elements will properly place themselves no matter what the resolution or aspect ratio is.