7

I just want to make a full screen game. I know how to change resolution on Windows but how do I change the resolution under Linux? Is there a cross platform QT solution for this? Also I've got borders around my GLWidget. How do I make the widget cover the entire window?

I'm just going to post the code:

#include <QtOpenGL> class GLWidget : public QGLWidget { public: void initializeGL() { glClearColor(0.0f, 0.0f, 1.0f, 0.0f); glClearDepth(1.0f); } void paintGL() { glClear(GL_COLOR_BUFFER_BIT); } void resizeGL(int width, int height) { int side = qMin(width, height); glViewport((width - side) / 2, (height - side) / 2, side, side); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-0.5f, +0.5f, -0.5f, +0.5f, 4.0f, 15.0f); glMatrixMode(GL_MODELVIEW); } }; int main(int argc, char *argv[]) { QApplication app(argc, argv); QDesktopWidget *desktop = app.desktop(); QWidget window; GLWidget *glWidget = new GLWidget; QHBoxLayout *mainLayout = new QHBoxLayout; mainLayout->addWidget(glWidget); window.setLayout(mainLayout); window.setWindowTitle("Hello GL"); window.resize(QSize(640, 480)); window.show(); window.showFullScreen(); return app.exec(); } 
5
  • 3
    SDL is probably a better toolkit for games than Qt. Commented Jul 9, 2012 at 0:07
  • 2
    Take a look at xrandr. Commented Jul 9, 2012 at 0:26
  • Someone already asked this. Commented Jul 9, 2012 at 7:04
  • Actually that's on windows. That does not provide an answer to my question. My best guess is that I need to use x window api to do it. However, this begs the question of why not just use the platform window library in the first place if I'm going to have to use it anyway? Also I really need to know how to remove the borders from the glwidget. Commented Jul 9, 2012 at 7:09
  • Setting the layout margins seem to fix the border problem but I'm not sure if that is the best way to do it. Is there anyway I can render directly to the window? Commented Jul 9, 2012 at 7:17

1 Answer 1

5

You can use xrrsetscreenconfigandrate, as explained here:

#include<stdio.h> #include<stdlib.h> #include<string.h> #include<unistd.h> #include<X11/Xlib.h> #include<X11/extensions/Xrandr.h> Display *dpy; Window root; int num_sizes; XRRScreenSize *xrrs; XRRScreenConfiguration *conf; short possible_frequencies[64][64]; short original_rate; Rotation original_rotation; SizeID original_size_id; int main(int argc, char *argv[]){ // // CONNECT TO X-SERVER, GET ROOT WINDOW ID // dpy = XOpenDisplay(NULL); root = RootWindow(dpy, 0); // // GET POSSIBLE SCREEN RESOLUTIONS // xrrs = XRRSizes(dpy, 0, &num_sizes); // // LOOP THROUGH ALL POSSIBLE RESOLUTIONS, // GETTING THE SELECTABLE DISPLAY FREQUENCIES // for(int i = 0; i < num_sizes; i ++) { short *rates; int num_rates; printf("\n\t%2i : %4i x %4i (%4imm x%4imm ) ", i, xrrs[i].width, xrrs[i].height, xrrs[i].mwidth, xrrs[i].mheight); rates = XRRRates(dpy, 0, i, &num_rates); for(int j = 0; j < num_rates; j ++) { possible_frequencies[i][j] = rates[j]; printf("%4i ", rates[j]); } } printf("\n"); // // GET CURRENT RESOLUTION AND FREQUENCY // conf = XRRGetScreenInfo(dpy, root); original_rate = XRRConfigCurrentRate(conf); original_size_id = XRRConfigCurrentConfiguration(conf, &original_rotation); printf("\n\tCURRENT SIZE ID : %i\n", original_size_id); printf("\tCURRENT ROTATION : %i \n", original_rotation); printf("\tCURRENT RATE : %i Hz\n\n", original_rate); // // CHANGE RESOLUTION // printf("\tCHANGED TO %i x %i PIXELS, %i Hz\n\n", xrrs[1].width, xrrs[1].height, possible_frequencies[1][0]); XRRSetScreenConfigAndRate(dpy, conf, root, 1, RR_Rotate_0, possible_frequencies[1][0], CurrentTime); // // SLEEP A WHILE // usleep(6000000); // // RESTORE ORIGINAL CONFIGURATION // printf("\tRESTORING %i x %i PIXELS, %i Hz\n\n", xrrs[original_size_id].width, xrrs[original_size_id].height, original_rate); XRRSetScreenConfigAndRate(dpy, conf, root, original_size_id, original_rotation, original_rate, CurrentTime); // // EXIT // XCloseDisplay(dpy); } // // gcc -o Xrandr Xrandr.cc -lX11 -lXrandr -lstdc++ // 
Sign up to request clarification or add additional context in comments.

1 Comment

That appears to be the best solution. Thank you fine sir!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.