我看过很多帖子,它们描述了有关LWJGL3和全屏的各种问题,但是似乎没人遇到我的问题。
基本上,在全屏模式下,窗口不会填满整个屏幕,但在窗口模式下,这样做不会有问题。 这是相关代码
public static void init() {
System.out.println(Logging.format("Window Dimensions: {0} / {1}", new Object[] { _height, _width }));
GLFWErrorCallback.createPrint(System.err).set();
if (!glfwInit())
throw new IllegalStateException("Unable to initialize GLFW");
if (_win != MemoryUtil.NULL)
closeWindow();
glfwDefaultWindowHints();
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
_win = glfwCreateWindow(_width, _height, _TITLE, _fullscreen ? glfwGetPrimaryMonitor(): MemoryUtil.NULL, 0);
windowSetup();
glEnable(GL_TEXTURE_2D);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
}
...
public static void windowSetup() {
if (_win == NULL)
throw new RuntimeException("Failed to create the GLFW window");
_displayData = glfwGetVideoMode(glfwGetPrimaryMonitor());
glfwDefaultWindowHints();
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
try (MemoryStack stack = stackPush()) {
IntBuffer pWidth = stack.mallocInt(1);
IntBuffer pHeight = stack.mallocInt(1);
glfwGetWindowSize(_win, pWidth, pHeight);
glfwSetWindowAspectRatio(_win, 16, 9);
if (!_fullscreen) {
glfwSetWindowPos(_win, (_displayData.width() - pWidth.get(0)) / 2, (_displayData.height() - pHeight.get(0)) / 2);
glfwShowWindow(_win);
} else {
glfwShowWindow(_win);
}
}
glfwMakeContextCurrent(_win);
if(_vsync) {
glfwSwapInterval(1);
} else {
glfwSwapInterval(0);
}
GL.createCapabilities();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
...
public static void toggleFullscreen() {
if (_fullscreen) {
_fullscreen = false;
} else {
_fullscreen = true;
}
long _fswin = glfwCreateWindow(_width, _height, _TITLE, _fullscreen ? glfwGetPrimaryMonitor() : MemoryUtil.NULL, _win);
glfwDestroyWindow(_win);
_win = _fswin;
windowSetup();
setCallbacks();
}
由Main中的此代码段驱动
if (canRender) {
// this swaps buffers
Renderer.render();
// this polls events
Window.update();
}