amarillion
amarillion

Reputation: 24937

Allegro 5 game: How do I set a resolution that is appropriate for the aspect ratio of the screen?

Using Allegro 5, how do initialize a game in fullscreen mode so that it respects the format of the screen (widescreen 16:9 vs normal 3:4)

al_create_display (w, h)

Let's you select any ratio you want. For example you can set 640x480, regardless of the screen size. But it will look weird on a widescreen monitor. How do you know which ratio to use?

Upvotes: 5

Views: 4752

Answers (1)

allefant
allefant

Reputation:

Hm, I can answer this as well - use al_get_monitor_info().

al_get_monitor_info(0, &info);
w = info.x2 - info.x1; /* Assume this is 1366 */
h = info.y2 - info.y1; /* Assume this is 768 */
al_create_display(w, h);

Now you can either render everything in a 640x480 rectangle centered within 1366x768 to make it appear pixel-perfect, or alternatively scale your graphics up by 768/480 and keep two black bars to the left and right. If you use OpenGL for rendering, both are very easy to do by simply altering the projection matrix.

Upvotes: 4

Related Questions