get_desktop_resolution(3)

πŸ“¦ version 4.4.3.1, in fedora 43, fedora 44

πŸ’– get_desktop_resolution β€” Allegro manual, bestie edition πŸ’–

okay so this one's from the Allegro manual, and it's genuinely one of those little functions that saves your whole entire life, no cap. let's get into it 🫢


✨ NAME ✨

get_desktop_resolution β€” finds out the desktop resolution. it's part of the Allegro game programming library. that's it, that's the vibe πŸ’…


🌸 SYNOPSIS 🌸

#include <allegro.h>

int get_desktop_resolution(int *width, int *height);

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so what this does is it finds out the currently selected desktop resolution. and like, why do you care? because you can use this info to avoid creating windows that are bigger than the current resolution πŸ’€ and that is especially important for some windowed drivers, because those literally can't create windows bigger than the desktop. it's giving "please respect the boundaries."

each parameter is a pointer to an integer, and one dimension of the screen gets stored in each one. so width gets a dimension, height gets a dimension. iconic, honestly.

⚠️ real talk bestie: under some OSes, switching to a full screen graphics mode may automatically change the desktop resolution. so you have to call this function before you set any graphics mode, otherwise you're not getting the real desktop resolution. like, you gotta ask before the glow-up, not after. periodt.

example time, because we love a demonstration:

int width, height;

allegro_init();
...
if (get_desktop_resolution(&width, &height) == 0) {
   /* Got the resolution correctly */
}

πŸ’€ RETURN VALUE πŸ’€

returns zero on success πŸŽ‰ or a negative number if this information is not available or does not apply. and if that happens? the values stored in the variables you provided for width and height are undefined. not zero, not null, not vibes β€” undefined. so don't go reading them like they mean something, bestie, that's a trap πŸ™ˆ


πŸ‘‘ SEE ALSO πŸ‘‘

go read those too, they're in the group chat already πŸ’œ


Allegro, version 4.4.3 β€” that's the source and the version, and honestly? iconic of them. this has been get_desktop_resolution(3) from the Allegro manual, tysm for coming to my TED talk, slay responsibly πŸ’…βœ¨πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from