我只想做一个全屏游戏。我知道如何在 Windows 上更改分辨率,但如何在 Linux 下更改分辨率?是否有针对此的跨平台 QT 解决方案?我的 GLWidget 周围也有边框。如何使小部件覆盖整个窗口?
我只是要发布代码:
#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();
}