虽然它可能无法直接回答这个问题,但我发现它是发布全屏和退出源代码的好地方。
使用 <GL/glut.h> 切换和恢复全屏
我的游戏.c
...
glutSpecialFunc(handleSpecial);
void handleSpecial(int key, int x, int y) {
oglHandleFullScreen(key, x, y);
}
...
如果您希望改为响应键盘事件 ( glutKeyboardFunc
),请确保将以下签名更改oglHandleFullScreen
为(unsigned char key, int x, int y)
.
全屏.h
void oglHandleFullScreen(int key, int x, int y);
void oglWindowed(int positionX, int positionY, int width, int height);
void oglFullScreen();
全屏.c
#include <GL/glut.h>
#include "fullscreen.h"
int isFullScreen = 0;
int previousPosition[2] = { 0, 0 };
int previousSize[2] = { 100, 100 };
void oglHandleFullScreen(int key, int x, int y) {
if (key != GLUT_KEY_F11) { // Respond to F11 key (glutSpecialFunc).
return;
}
if (isFullScreen) {
oglWindowed(previousPosition[0], previousPosition[1],
previousSize[0], previousSize[1]);
} else {
previousPosition[0] = glutGet(GLUT_WINDOW_X);
previousPosition[1] = glutGet(GLUT_WINDOW_Y);
previousSize[0] = glutGet(GLUT_WINDOW_WIDTH);
previousSize[1] = glutGet(GLUT_WINDOW_HEIGHT);
oglFullScreen();
}
isFullScreen = !isFullScreen;
}
void oglWindowed(int positionX, int positionY, int width, int height) {
glutReshapeWindow(width, height);
glutPositionWindow(positionX, positionY);
}
void oglFullScreen() {
glutFullScreen();
}