I'm working on my little game library again... and now I'm trying to change the screen resolution to match that of the window I'm making.
I thought that glutEnterGameMode would change the resolution but this is not the case, so I came up with a little hack.
util.cpp:
Code:
#include <cstdlib>
#include <iostream>
#include <GL/glut.h>
static int original_w, original_h;
void reset_resolution(void)
{
char mode[50];
sprintf(mode,"xrandr --size %dx%d",original_w,original_h);
system(mode);
}
void make_window(int w, int h, char *title, int fullscreen)
{
if (fullscreen) {
original_w = glutGet(GLUT_SCREEN_WIDTH);
original_h = glutGet(GLUT_SCREEN_HEIGHT);
char mode[50];
sprintf(mode,"xrandr --size %dx%d",w,h);
system(mode);
atexit(reset_resolution);
sprintf(mode,"%dx%d:32",w,h);
glutGameModeString(mode);
glutEnterGameMode();
}
else {
glutInitWindowSize(w,h);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutCreateWindow(title);
}
}
I know all about the danger of using calls to system(). So surely there must be a better way to go about changing the resolution. Actually a cross-platform method would be preferable but from what I've read X doesn't play nice with programs trying to change the mode.